diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-12-04 04:52:34 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-12-04 04:52:34 +0000 |
| commit | fefe45978623a7f8dd7e0496fe4877e64d875e2c (patch) | |
| tree | e7ad50bdffe89a0f471bdec365d9f27698e393d7 /Graphics | |
| parent | Removed DRAW_FLAG_TRANSITION_VERTEX_BUFFERS, DRAW_FLAG_TRANSITION_INDEX_BUFFE... (diff) | |
| download | DiligentCore-fefe45978623a7f8dd7e0496fe4877e64d875e2c.tar.gz DiligentCore-fefe45978623a7f8dd7e0496fe4877e64d875e2c.zip | |
Replaced SET_RENDER_TARGETS_FLAGS with RESOURCE_STATE_TRANSITION_MODE.
Removed CLEAR_DEPTH_STENCIL_TRANSITION_STATE_FLAG and CLEAR_DEPTH_STENCIL_VERIFY_STATE_FLAG
Diffstat (limited to 'Graphics')
20 files changed, 130 insertions, 143 deletions
diff --git a/Graphics/GraphicsEngine/interface/DeviceContext.h b/Graphics/GraphicsEngine/interface/DeviceContext.h index 80d7cb9f..64da424c 100644 --- a/Graphics/GraphicsEngine/interface/DeviceContext.h +++ b/Graphics/GraphicsEngine/interface/DeviceContext.h @@ -163,11 +163,9 @@ struct DrawAttribs /// These flags are used by IDeviceContext::ClearDepthStencil(). enum CLEAR_DEPTH_STENCIL_FLAGS : Uint32 { - CLEAR_DEPTH_FLAG_NONE = 0x00, ///< Perform no clear no transitions - CLEAR_DEPTH_FLAG = 0x01, ///< Clear depth part of the buffer - CLEAR_STENCIL_FLAG = 0x02, ///< Clear stencil part of the buffer - CLEAR_DEPTH_STENCIL_TRANSITION_STATE_FLAG = 0x04, ///< Transition depth-stencil buffer to required state - CLEAR_DEPTH_STENCIL_VERIFY_STATE_FLAG = 0x08 ///< Verify the state is correct (debug and development builds only) + CLEAR_DEPTH_FLAG_NONE = 0x00, ///< Perform no clear no transitions + CLEAR_DEPTH_FLAG = 0x01, ///< Clear depth part of the buffer + CLEAR_STENCIL_FLAG = 0x02 ///< Clear stencil part of the buffer }; DEFINE_FLAG_ENUM_OPERATORS(CLEAR_DEPTH_STENCIL_FLAGS) @@ -236,32 +234,6 @@ enum SET_VERTEX_BUFFERS_FLAGS : Uint8 DEFINE_FLAG_ENUM_OPERATORS(SET_VERTEX_BUFFERS_FLAGS) -/// Additional flags for IDeviceContext::SetRenderTargets() command that define -/// which resources need to be transitioned by the command. -enum SET_RENDER_TARGETS_FLAGS : Uint32 -{ - /// Perform no state transitions - SET_RENDER_TARGETS_FLAG_NONE = 0x00, - - /// Transition color targets to Diligent::RESOURCE_STATE_RENDER_TARGET state (see Diligent::RESOURCE_STATE). - /// Textures in unknown state will not be transitioned. - SET_RENDER_TARGETS_FLAG_TRANSITION_COLOR = 0x01, - - /// Transition depth buffer to Diligent::RESOURCE_STATE_DEPTH_WRITE state (see Diligent::RESOURCE_STATE). - /// If the texture is in unknown state, the flag will have no effect. - SET_RENDER_TARGETS_FLAG_TRANSITION_DEPTH = 0x02, - - /// Transition all color targets and depth buffer - SET_RENDER_TARGETS_FLAG_TRANSITION_ALL = (SET_RENDER_TARGETS_FLAG_TRANSITION_COLOR | SET_RENDER_TARGETS_FLAG_TRANSITION_DEPTH), - - /// Verify the state of color/depth targets not being transitioned. This flag - /// only has effect in debug and development builds. No validation is performed - /// in release build and the flag is ignored. - SET_RENDER_TARGETS_FLAG_VERIFY_STATES = 0x04 -}; -DEFINE_FLAG_ENUM_OPERATORS(SET_RENDER_TARGETS_FLAGS) - - /// Describes the viewport. /// This structure is used by IDeviceContext::SetViewports(). @@ -565,27 +537,27 @@ public: /// Binds one or more render targets and the depth-stencil buffer to the pipeline. It also /// sets the viewport to match the first non-null render target or depth-stencil buffer. - /// \param [in] NumRenderTargets - Number of render targets to bind. - /// \param [in] ppRenderTargets - Array of pointers to ITextureView that represent the render - /// targets to bind to the device. The type of each view in the - /// array must be Diligent::TEXTURE_VIEW_RENDER_TARGET. - /// \param [in] pDepthStencil - Pointer to the ITextureView that represents the depth stencil to - /// bind to the device. The view type must be - /// Diligent::TEXTURE_VIEW_DEPTH_STENCIL. - /// \param [in] Flags - Flags defining required resource transitions. - /// \remarks - /// The device context will keep strong references to all bound render target - /// and depth-stencil views. Thus these views (and consequently referenced textures) - /// cannot be released until they are unbound from the context.\n - /// Any render targets not defined by this call are set to nullptr.\n\n - /// You can set the default render target and depth stencil using the - /// following call: + /// \param [in] NumRenderTargets - Number of render targets to bind. + /// \param [in] ppRenderTargets - Array of pointers to ITextureView that represent the render + /// targets to bind to the device. The type of each view in the + /// array must be Diligent::TEXTURE_VIEW_RENDER_TARGET. + /// \param [in] pDepthStencil - Pointer to the ITextureView that represents the depth stencil to + /// bind to the device. The view type must be + /// Diligent::TEXTURE_VIEW_DEPTH_STENCIL. + /// \param [in] StateTransitionMode - State transition mode of the render targets and depth stencil buffer being set (see Diligent::RESOURCE_STATE_TRANSITION_MODE). + /// + /// \remarks The device context will keep strong references to all bound render target + /// and depth-stencil views. Thus these views (and consequently referenced textures) + /// cannot be released until they are unbound from the context.\n + /// Any render targets not defined by this call are set to nullptr.\n\n + /// You can set the default render target and depth stencil using the + /// following call: /// /// pContext->SetRenderTargets(0, nullptr, nullptr); - virtual void SetRenderTargets(Uint32 NumRenderTargets, - ITextureView* ppRenderTargets[], - ITextureView* pDepthStencil, - SET_RENDER_TARGETS_FLAGS Flags) = 0; + virtual void SetRenderTargets(Uint32 NumRenderTargets, + ITextureView* ppRenderTargets[], + ITextureView* pDepthStencil, + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) = 0; /// Executes a draw command @@ -620,15 +592,17 @@ public: /// \param [in] pView - Pointer to ITextureView interface to clear. The view type must be /// Diligent::TEXTURE_VIEW_DEPTH_STENCIL. + /// \param [in] StateTransitionMode - state transition mode of the depth-stencil buffer to clear. /// \param [in] ClearFlags - Idicates which parts of the buffer to clear, see Diligent::CLEAR_DEPTH_STENCIL_FLAGS. /// \param [in] fDepth - Value to clear depth part of the view with. /// \param [in] Stencil - Value to clear stencil part of the view with. /// \remarks The full extent of the view is always cleared. Viewport and scissor settings are not applied. /// \note The depth-stencil view must be bound to the pipeline for clear operation to be performed. - virtual void ClearDepthStencil(ITextureView* pView, - CLEAR_DEPTH_STENCIL_FLAGS ClearFlags = CLEAR_DEPTH_FLAG | CLEAR_DEPTH_STENCIL_TRANSITION_STATE_FLAG, - float fDepth = 1.f, - Uint8 Stencil = 0) = 0; + virtual void ClearDepthStencil(ITextureView* pView, + CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, + float fDepth, + Uint8 Stencil, + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) = 0; /// Clears a render target view diff --git a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h index 445891fa..d351155c 100755 --- a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h @@ -86,16 +86,20 @@ public: virtual void SetScissorRects(Uint32 NumRects, const Rect* pRects, Uint32 RTWidth, Uint32 RTHeight)override final;
- virtual void SetRenderTargets(Uint32 NumRenderTargets,
- ITextureView* ppRenderTargets[],
- ITextureView* pDepthStencil,
- SET_RENDER_TARGETS_FLAGS Flags)override final;
+ virtual void SetRenderTargets(Uint32 NumRenderTargets,
+ ITextureView* ppRenderTargets[],
+ ITextureView* pDepthStencil,
+ RESOURCE_STATE_TRANSITION_MODE StateTransitionMode)override final;
virtual void Draw(DrawAttribs& DrawAttribs)override final;
virtual void DispatchCompute(const DispatchComputeAttribs& DispatchAttrs)override final;
- virtual void ClearDepthStencil(ITextureView* pView, CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, float fDepth, Uint8 Stencil)override final;
+ virtual void ClearDepthStencil(ITextureView* pView,
+ CLEAR_DEPTH_STENCIL_FLAGS ClearFlags,
+ float fDepth,
+ Uint8 Stencil,
+ RESOURCE_STATE_TRANSITION_MODE StateTransitionMode)override final;
virtual void ClearRenderTarget(ITextureView* pView, const float* RGBA, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode)override final;
diff --git a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp index ae00279c..01443e9d 100755 --- a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp @@ -861,7 +861,11 @@ namespace Diligent m_pd3d11DeviceContext->Dispatch( DispatchAttrs.ThreadGroupCountX, DispatchAttrs.ThreadGroupCountY, DispatchAttrs.ThreadGroupCountZ );
}
- void DeviceContextD3D11Impl::ClearDepthStencil( ITextureView* pView, CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, float fDepth, Uint8 Stencil )
+ void DeviceContextD3D11Impl::ClearDepthStencil(ITextureView* pView,
+ CLEAR_DEPTH_STENCIL_FLAGS ClearFlags,
+ float fDepth,
+ Uint8 Stencil,
+ RESOURCE_STATE_TRANSITION_MODE StateTransitionMode)
{
if (pView == nullptr)
{
@@ -1554,7 +1558,10 @@ namespace Diligent m_pd3d11DeviceContext->OMSetRenderTargets(0, nullptr, nullptr);
}
- void DeviceContextD3D11Impl::SetRenderTargets( Uint32 NumRenderTargets, ITextureView* ppRenderTargets[], ITextureView* pDepthStencil, SET_RENDER_TARGETS_FLAGS Flags )
+ void DeviceContextD3D11Impl::SetRenderTargets(Uint32 NumRenderTargets,
+ ITextureView* ppRenderTargets[],
+ ITextureView* pDepthStencil,
+ RESOURCE_STATE_TRANSITION_MODE StateTransitionMode)
{
if (TDeviceContextBase::SetRenderTargets( NumRenderTargets, ppRenderTargets, pDepthStencil))
{
@@ -1563,14 +1570,14 @@ namespace Diligent if (ppRenderTargets[RT])
{
auto* pTex = ValidatedCast<TextureBaseD3D11>(ppRenderTargets[RT]->GetTexture());
- if (Flags & SET_RENDER_TARGETS_FLAG_TRANSITION_COLOR)
+ if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_TRANSITION)
{
UnbindTextureFromInput( pTex, pTex->GetD3D11Texture() );
if (pTex->IsInKnownState())
pTex->SetState(RESOURCE_STATE_RENDER_TARGET);
}
#ifdef DEVELOPMENT
- else if (Flags & SET_RENDER_TARGETS_FLAG_VERIFY_STATES)
+ else if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY)
{
DvpVerifyTextureState(*pTex, RESOURCE_STATE_RENDER_TARGET, "Setting render targets (DeviceContextD3D11Impl::SetRenderTargets)");
}
@@ -1581,14 +1588,14 @@ namespace Diligent if (pDepthStencil)
{
auto* pTex = ValidatedCast<TextureBaseD3D11>(pDepthStencil->GetTexture());
- if (Flags & SET_RENDER_TARGETS_FLAG_TRANSITION_DEPTH)
+ if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_TRANSITION)
{
UnbindTextureFromInput( pTex, pTex->GetD3D11Texture() );
if (pTex->IsInKnownState())
pTex->SetState(RESOURCE_STATE_DEPTH_WRITE);
}
#ifdef DEVELOPMENT
- else if(Flags & SET_RENDER_TARGETS_FLAG_VERIFY_STATES)
+ else if(StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY)
{
DvpVerifyTextureState(*pTex, RESOURCE_STATE_DEPTH_WRITE, "Setting depth-stencil buffer (DeviceContextD3D11Impl::SetRenderTargets)");
}
diff --git a/Graphics/GraphicsEngineD3D11/src/RenderDeviceFactoryD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/RenderDeviceFactoryD3D11.cpp index ca7c9e9e..019e1885 100644 --- a/Graphics/GraphicsEngineD3D11/src/RenderDeviceFactoryD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/RenderDeviceFactoryD3D11.cpp @@ -324,7 +324,7 @@ void EngineFactoryD3D11Impl::CreateSwapChainD3D11( IRenderDevice* pDe pDeviceContextD3D11->SetSwapChain(pSwapChainD3D11); // Bind default render target - pDeviceContextD3D11->SetRenderTargets( 0, nullptr, nullptr, SET_RENDER_TARGETS_FLAG_TRANSITION_ALL ); + pDeviceContextD3D11->SetRenderTargets( 0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION ); // Set default viewport pDeviceContextD3D11->SetViewports( 1, nullptr, 0, 0 ); diff --git a/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp index 20379c42..720b155f 100644 --- a/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp @@ -182,7 +182,7 @@ void SwapChainD3D11Impl::UpdateSwapChain(bool CreateNew) if (bIsDefaultFBBound) { // Set default render target and viewport - pImmediateCtxD3D11->SetRenderTargets(0, nullptr, nullptr, SET_RENDER_TARGETS_FLAG_TRANSITION_ALL); + pImmediateCtxD3D11->SetRenderTargets(0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); pImmediateCtxD3D11->SetViewports(1, nullptr, 0, 0); } } diff --git a/Graphics/GraphicsEngineD3D12/include/CommandContext.h b/Graphics/GraphicsEngineD3D12/include/CommandContext.h index c3f33491..49fd72bd 100644 --- a/Graphics/GraphicsEngineD3D12/include/CommandContext.h +++ b/Graphics/GraphicsEngineD3D12/include/CommandContext.h @@ -203,8 +203,6 @@ public: } } - void SetRenderTargets( UINT NumRTVs, ITextureViewD3D12** ppRTVs, ITextureViewD3D12* pDSV, SET_RENDER_TARGETS_FLAGS Flags ); - void SetViewports( UINT NumVPs, const D3D12_VIEWPORT* pVPs ) { m_pCommandList->RSSetViewports(NumVPs, pVPs); diff --git a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h index e5e160be..7861ffe9 100644 --- a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h @@ -88,16 +88,20 @@ public: virtual void SetScissorRects( Uint32 NumRects, const Rect* pRects, Uint32 RTWidth, Uint32 RTHeight )override final; - virtual void SetRenderTargets( Uint32 NumRenderTargets, - ITextureView* ppRenderTargets[], - ITextureView* pDepthStencil, - SET_RENDER_TARGETS_FLAGS Flags )override final; + virtual void SetRenderTargets( Uint32 NumRenderTargets, + ITextureView* ppRenderTargets[], + ITextureView* pDepthStencil, + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode )override final; virtual void Draw( DrawAttribs& DrawAttribs )override final; virtual void DispatchCompute( const DispatchComputeAttribs& DispatchAttrs )override final; - virtual void ClearDepthStencil( ITextureView* pView, CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, float fDepth, Uint8 Stencil)override final; + virtual void ClearDepthStencil(ITextureView* pView, + CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, + float fDepth, + Uint8 Stencil, + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode)override final; virtual void ClearRenderTarget( ITextureView* pView, const float* RGBA, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode )override final; @@ -215,7 +219,7 @@ public: private: void CommitD3D12IndexBuffer(VALUE_TYPE IndexType); void CommitD3D12VertexBuffers(class GraphicsContext& GraphCtx); - void CommitRenderTargets(SET_RENDER_TARGETS_FLAGS Flags); + void CommitRenderTargets(RESOURCE_STATE_TRANSITION_MODE StateTransitionMode); void CommitViewports(); void CommitScissorRects(class GraphicsContext &GraphCtx, bool ScissorEnable); void Flush(bool RequestNewCmdCtx); diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp index afa16772..9fdaf3bb 100644 --- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp @@ -211,7 +211,7 @@ namespace Diligent { GraphicsCtx.SetStencilRef(m_StencilRef); GraphicsCtx.SetBlendFactor(m_BlendFactors); - CommitRenderTargets(SET_RENDER_TARGETS_FLAG_VERIFY_STATES); + CommitRenderTargets(RESOURCE_STATE_TRANSITION_MODE_VERIFY); CommitViewports(); } @@ -482,7 +482,11 @@ namespace Diligent ++m_State.NumCommands; } - void DeviceContextD3D12Impl::ClearDepthStencil( ITextureView* pView, CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, float fDepth, Uint8 Stencil ) + void DeviceContextD3D12Impl::ClearDepthStencil(ITextureView* pView, + CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, + float fDepth, + Uint8 Stencil, + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) { ITextureViewD3D12* pViewD3D12 = nullptr; if( pView != nullptr ) @@ -508,13 +512,7 @@ namespace Diligent auto* pTextureD3D12 = ValidatedCast<TextureD3D12Impl>( pViewD3D12->GetTexture() ); auto& CmdCtx = GetCmdContext(); - auto TransitionMode = - (ClearFlags & CLEAR_DEPTH_STENCIL_TRANSITION_STATE_FLAG) ? - RESOURCE_STATE_TRANSITION_MODE_TRANSITION : - ((ClearFlags & CLEAR_DEPTH_STENCIL_VERIFY_STATE_FLAG) ? - RESOURCE_STATE_TRANSITION_MODE_VERIFY : - RESOURCE_STATE_TRANSITION_MODE_NONE); - TransitionOrVerifyTextureState(CmdCtx, *pTextureD3D12, TransitionMode, RESOURCE_STATE_DEPTH_WRITE, "Clearing depth-stencil buffer (DeviceContextD3D12Impl::ClearDepthStencil)"); + TransitionOrVerifyTextureState(CmdCtx, *pTextureD3D12, StateTransitionMode, RESOURCE_STATE_DEPTH_WRITE, "Clearing depth-stencil buffer (DeviceContextD3D12Impl::ClearDepthStencil)"); D3D12_CLEAR_FLAGS d3d12ClearFlags = (D3D12_CLEAR_FLAGS)0; if( ClearFlags & CLEAR_DEPTH_FLAG ) d3d12ClearFlags |= D3D12_CLEAR_FLAG_DEPTH; @@ -777,7 +775,7 @@ namespace Diligent } } - void DeviceContextD3D12Impl::CommitRenderTargets(SET_RENDER_TARGETS_FLAGS Flags) + void DeviceContextD3D12Impl::CommitRenderTargets(RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) { const Uint32 MaxD3D12RTs = D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT; Uint32 NumRenderTargets = m_NumBoundRenderTargets; @@ -816,12 +814,7 @@ namespace Diligent if( auto* pRTV = ppRTVs[i] ) { auto* pTexture = ValidatedCast<TextureD3D12Impl>( pRTV->GetTexture() ); - auto RTTransitionMode = (Flags & SET_RENDER_TARGETS_FLAG_TRANSITION_COLOR) ? - RESOURCE_STATE_TRANSITION_MODE_TRANSITION : - ((Flags & SET_RENDER_TARGETS_FLAG_VERIFY_STATES) ? - RESOURCE_STATE_TRANSITION_MODE_VERIFY : - RESOURCE_STATE_TRANSITION_MODE_NONE); - TransitionOrVerifyTextureState(CmdCtx, *pTexture, RTTransitionMode, RESOURCE_STATE_RENDER_TARGET, "Setting render targets (DeviceContextD3D12Impl::CommitRenderTargets)"); + TransitionOrVerifyTextureState(CmdCtx, *pTexture, StateTransitionMode, RESOURCE_STATE_RENDER_TARGET, "Setting render targets (DeviceContextD3D12Impl::CommitRenderTargets)"); RTVHandles[i] = pRTV->GetCPUDescriptorHandle(); VERIFY_EXPR(RTVHandles[i].ptr != 0); } @@ -837,12 +830,7 @@ namespace Diligent //} //else { - auto DepthTransitionMode = (Flags & SET_RENDER_TARGETS_FLAG_TRANSITION_DEPTH) ? - RESOURCE_STATE_TRANSITION_MODE_TRANSITION : - ((Flags & SET_RENDER_TARGETS_FLAG_VERIFY_STATES) ? - RESOURCE_STATE_TRANSITION_MODE_VERIFY : - RESOURCE_STATE_TRANSITION_MODE_NONE); - TransitionOrVerifyTextureState(CmdCtx, *pTexture, DepthTransitionMode, RESOURCE_STATE_DEPTH_WRITE, "Setting depth-stencil buffer (DeviceContextD3D12Impl::CommitRenderTargets)"); + TransitionOrVerifyTextureState(CmdCtx, *pTexture, StateTransitionMode, RESOURCE_STATE_DEPTH_WRITE, "Setting depth-stencil buffer (DeviceContextD3D12Impl::CommitRenderTargets)"); DSVHandle = pDSV->GetCPUDescriptorHandle(); VERIFY_EXPR(DSVHandle.ptr != 0); } @@ -853,11 +841,14 @@ namespace Diligent CmdCtx.AsGraphicsContext().GetCommandList()->OMSetRenderTargets( NumRenderTargets, RTVHandles, FALSE, DSVHandle.ptr != 0 ? &DSVHandle : nullptr ); } - void DeviceContextD3D12Impl::SetRenderTargets( Uint32 NumRenderTargets, ITextureView *ppRenderTargets[], ITextureView *pDepthStencil, SET_RENDER_TARGETS_FLAGS Flags ) + void DeviceContextD3D12Impl::SetRenderTargets( Uint32 NumRenderTargets, + ITextureView* ppRenderTargets[], + ITextureView* pDepthStencil, + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode ) { if( TDeviceContextBase::SetRenderTargets( NumRenderTargets, ppRenderTargets, pDepthStencil ) ) { - CommitRenderTargets(Flags); + CommitRenderTargets(StateTransitionMode); // Set the viewport to match the render target size SetViewports(1, nullptr, 0, 0); diff --git a/Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp index 88681445..31dea0fc 100644 --- a/Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp @@ -381,7 +381,7 @@ void EngineFactoryD3D12Impl::CreateSwapChainD3D12( IRenderDevice* pDe pDeviceContextD3D12->SetSwapChain(pSwapChainD3D12); // Bind default render target - pDeviceContextD3D12->SetRenderTargets( 0, nullptr, nullptr, SET_RENDER_TARGETS_FLAG_TRANSITION_ALL ); + pDeviceContextD3D12->SetRenderTargets( 0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION ); // Set default viewport pDeviceContextD3D12->SetViewports( 1, nullptr, 0, 0 ); diff --git a/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp index 18ef3043..357755db 100644 --- a/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp @@ -199,7 +199,7 @@ void SwapChainD3D12Impl::UpdateSwapChain(bool CreateNew) if (bIsDefaultFBBound) { // Set default render target and viewport - pDeviceContext->SetRenderTargets(0, nullptr, nullptr, SET_RENDER_TARGETS_FLAG_TRANSITION_ALL); + pDeviceContext->SetRenderTargets(0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); pDeviceContext->SetViewports(1, nullptr, 0, 0); } } diff --git a/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.h index e0647f20..ec04b56d 100644 --- a/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.h +++ b/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.h @@ -78,13 +78,20 @@ public: virtual void SetScissorRects( Uint32 NumRects, const Rect *pRects, Uint32 RTWidth, Uint32 RTHeight )override final; - virtual void SetRenderTargets( Uint32 NumRenderTargets, ITextureView *ppRenderTargets[], ITextureView *pDepthStencil, SET_RENDER_TARGETS_FLAGS Flags )override final; + virtual void SetRenderTargets( Uint32 NumRenderTargets, + ITextureView* ppRenderTargets[], + ITextureView* pDepthStencil, + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode )override final; virtual void Draw( DrawAttribs &DrawAttribs )override final; virtual void DispatchCompute( const DispatchComputeAttribs &DispatchAttrs )override final; - virtual void ClearDepthStencil( ITextureView *pView, CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, float fDepth, Uint8 Stencil)override final; + virtual void ClearDepthStencil(ITextureView* pView, + CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, + float fDepth, + Uint8 Stencil, + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode)override final; virtual void ClearRenderTarget( ITextureView *pView, const float *RGBA, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode )override final; diff --git a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp index 8c33daa1..672ce3ab 100644 --- a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp @@ -334,7 +334,10 @@ namespace Diligent SetViewports(1, nullptr, 0, 0); } - void DeviceContextGLImpl::SetRenderTargets( Uint32 NumRenderTargets, ITextureView *ppRenderTargets[], ITextureView *pDepthStencil, SET_RENDER_TARGETS_FLAGS Flags ) + void DeviceContextGLImpl::SetRenderTargets( Uint32 NumRenderTargets, + ITextureView* ppRenderTargets[], + ITextureView* pDepthStencil, + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode ) { if( TDeviceContextBase::SetRenderTargets( NumRenderTargets, ppRenderTargets, pDepthStencil ) ) CommitRenderTargets(); @@ -871,7 +874,11 @@ namespace Diligent #endif } - void DeviceContextGLImpl::ClearDepthStencil( ITextureView *pView, CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, float fDepth, Uint8 Stencil ) + void DeviceContextGLImpl::ClearDepthStencil(ITextureView* pView, + CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, + float fDepth, + Uint8 Stencil, + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) { // Unlike OpenGL, in D3D10+, the full extent of the resource view is always cleared. // Viewport and scissor settings are not applied. diff --git a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp index ea53ee57..94057326 100644 --- a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp @@ -128,7 +128,7 @@ void EngineFactoryOpenGLImpl::CreateDeviceAndSwapChainGL(const EngineGLAttribs& pDeviceContextOpenGL->SetSwapChain(pSwapChainGL); // Bind default framebuffer and viewport - pDeviceContextOpenGL->SetRenderTargets( 0, nullptr, nullptr, SET_RENDER_TARGETS_FLAG_TRANSITION_ALL ); + pDeviceContextOpenGL->SetRenderTargets( 0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION ); pDeviceContextOpenGL->SetViewports( 1, nullptr, 0, 0 ); } catch( const std::runtime_error & ) diff --git a/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp index 2d46e3c0..d7fb3b06 100644 --- a/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp @@ -105,7 +105,7 @@ void SwapChainGLImpl::Resize( Uint32 NewWidth, Uint32 NewHeight ) if( bIsDefaultFBBound ) { // Update framebuffer size and viewport - pImmediateCtxGL->SetRenderTargets(0, nullptr, nullptr, SET_RENDER_TARGETS_FLAG_TRANSITION_ALL); + pImmediateCtxGL->SetRenderTargets(0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); pImmediateCtxGL->SetViewports( 1, nullptr, 0, 0 ); } } diff --git a/Graphics/GraphicsEngineOpenGL/src/TexRegionRender.cpp b/Graphics/GraphicsEngineOpenGL/src/TexRegionRender.cpp index f380a404..715025bf 100644 --- a/Graphics/GraphicsEngineOpenGL/src/TexRegionRender.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/TexRegionRender.cpp @@ -162,7 +162,7 @@ namespace Diligent void TexRegionRender::RestoreStates( DeviceContextGLImpl *pCtxGL ) { - pCtxGL->SetRenderTargets( m_NumRenderTargets, m_pOrigRTVs, m_pOrigDSV, SET_RENDER_TARGETS_FLAG_TRANSITION_ALL ); + pCtxGL->SetRenderTargets( m_NumRenderTargets, m_pOrigRTVs, m_pOrigDSV, RESOURCE_STATE_TRANSITION_MODE_TRANSITION ); for( Uint32 rt = 0; rt < _countof( m_pOrigRTVs ); ++rt ) { if( m_pOrigRTVs[rt] ) diff --git a/Graphics/GraphicsEngineOpenGL/src/TextureBaseGL.cpp b/Graphics/GraphicsEngineOpenGL/src/TextureBaseGL.cpp index 2ccd76bf..a09cd189 100644 --- a/Graphics/GraphicsEngineOpenGL/src/TextureBaseGL.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/TextureBaseGL.cpp @@ -468,7 +468,7 @@ void TextureBaseGL :: CopyData(DeviceContextGLImpl *pDeviceCtxGL, ); ITextureView *pRTVs[] = { &RTV }; - pDeviceCtxGL->SetRenderTargets( _countof( pRTVs ), pRTVs, nullptr, SET_RENDER_TARGETS_FLAG_TRANSITION_ALL ); + pDeviceCtxGL->SetRenderTargets( _countof( pRTVs ), pRTVs, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION ); // No need to set up the viewport as SetRenderTargets() does that diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h index 19659935..35274c2b 100644 --- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h @@ -95,16 +95,20 @@ public: virtual void SetScissorRects( Uint32 NumRects, const Rect* pRects, Uint32 RTWidth, Uint32 RTHeight )override final; - virtual void SetRenderTargets( Uint32 NumRenderTargets, - ITextureView* ppRenderTargets[], - ITextureView* pDepthStencil, - SET_RENDER_TARGETS_FLAGS Flags )override final; + virtual void SetRenderTargets( Uint32 NumRenderTargets, + ITextureView* ppRenderTargets[], + ITextureView* pDepthStencil, + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode )override final; virtual void Draw( DrawAttribs &DrawAttribs )override final; virtual void DispatchCompute( const DispatchComputeAttribs& DispatchAttrs )override final; - virtual void ClearDepthStencil( ITextureView* pView, CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, float fDepth, Uint8 Stencil)override final; + virtual void ClearDepthStencil(ITextureView* pView, + CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, + float fDepth, + Uint8 Stencil, + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode)override final; virtual void ClearRenderTarget( ITextureView* pView, const float* RGBA, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode )override final; @@ -244,7 +248,7 @@ public: Int64 GetContextFrameNumber()const{return m_ContextFrameNumber;} private: - void TransitionRenderTargets(SET_RENDER_TARGETS_FLAGS Flags); + void TransitionRenderTargets(RESOURCE_STATE_TRANSITION_MODE StateTransitionMode); inline void CommitRenderPassAndFramebuffer(); void CommitVkVertexBuffers(); void CommitViewports(); diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 26a5fa06..754325fe 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -384,7 +384,7 @@ namespace Diligent EnsureVkCmdBuffer(); - const bool VerifyStates = drawAttribs.Flags & DRAW_FLAG_VERIFY_STATES; + const bool VerifyStates = (drawAttribs.Flags & DRAW_FLAG_VERIFY_STATES) != 0; if ( drawAttribs.IsIndexed ) { #ifdef DEVELOPMENT @@ -518,7 +518,11 @@ namespace Diligent ++m_State.NumCommands; } - void DeviceContextVkImpl::ClearDepthStencil( ITextureView* pView, CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, float fDepth, Uint8 Stencil ) + void DeviceContextVkImpl::ClearDepthStencil(ITextureView* pView, + CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, + float fDepth, + Uint8 Stencil, + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) { ITextureViewVk* pVkDSV = nullptr; if ( pView != nullptr ) @@ -586,13 +590,7 @@ namespace Diligent auto* pTextureVk = ValidatedCast<TextureVkImpl>(pTexture); // Image layout must be VK_IMAGE_LAYOUT_GENERAL or VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL (17.1) - auto TransitionMode = - (ClearFlags & CLEAR_DEPTH_STENCIL_TRANSITION_STATE_FLAG) ? - RESOURCE_STATE_TRANSITION_MODE_TRANSITION : - ((ClearFlags & CLEAR_DEPTH_STENCIL_VERIFY_STATE_FLAG) ? - RESOURCE_STATE_TRANSITION_MODE_VERIFY : - RESOURCE_STATE_TRANSITION_MODE_NONE); - TransitionOrVerifyTextureState(*pTextureVk, TransitionMode, RESOURCE_STATE_COPY_DEST, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + TransitionOrVerifyTextureState(*pTextureVk, StateTransitionMode, RESOURCE_STATE_COPY_DEST, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "Clearing depth-stencil buffer outside of render pass (DeviceContextVkImpl::ClearDepthStencil)"); VkClearDepthStencilValue ClearValue; @@ -979,18 +977,13 @@ namespace Diligent } - void DeviceContextVkImpl::TransitionRenderTargets(SET_RENDER_TARGETS_FLAGS Flags) + void DeviceContextVkImpl::TransitionRenderTargets(RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) { if (m_pBoundDepthStencil) { auto* pDSVVk = m_pBoundDepthStencil.RawPtr<TextureViewVkImpl>(); auto* pDepthBufferVk = ValidatedCast<TextureVkImpl>(pDSVVk->GetTexture()); - auto DepthTransitionMode = (Flags & SET_RENDER_TARGETS_FLAG_TRANSITION_DEPTH) ? - RESOURCE_STATE_TRANSITION_MODE_TRANSITION : - ((Flags & SET_RENDER_TARGETS_FLAG_VERIFY_STATES) ? - RESOURCE_STATE_TRANSITION_MODE_VERIFY : - RESOURCE_STATE_TRANSITION_MODE_NONE); - TransitionOrVerifyTextureState(*pDepthBufferVk, DepthTransitionMode, RESOURCE_STATE_DEPTH_WRITE, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, + TransitionOrVerifyTextureState(*pDepthBufferVk, StateTransitionMode, RESOURCE_STATE_DEPTH_WRITE, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, "Binding depth-stencil buffer (DeviceContextVkImpl::TransitionRenderTargets)"); } @@ -1000,12 +993,7 @@ namespace Diligent { auto* pRTVVk = ValidatedCast<TextureViewVkImpl>(pRTV); auto* pRenderTargetVk = ValidatedCast<TextureVkImpl>(pRTVVk->GetTexture()); - auto RTTransitionMode = (Flags & SET_RENDER_TARGETS_FLAG_TRANSITION_COLOR) ? - RESOURCE_STATE_TRANSITION_MODE_TRANSITION : - ((Flags & SET_RENDER_TARGETS_FLAG_VERIFY_STATES) ? - RESOURCE_STATE_TRANSITION_MODE_VERIFY : - RESOURCE_STATE_TRANSITION_MODE_NONE); - TransitionOrVerifyTextureState(*pRenderTargetVk, RTTransitionMode, RESOURCE_STATE_RENDER_TARGET, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, + TransitionOrVerifyTextureState(*pRenderTargetVk, StateTransitionMode, RESOURCE_STATE_RENDER_TARGET, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, "Binding render targets (DeviceContextVkImpl::TransitionRenderTargets)"); } } @@ -1023,14 +1011,17 @@ namespace Diligent { VERIFY_EXPR(m_RenderPass != VK_NULL_HANDLE); #ifdef DEVELOPMENT - TransitionRenderTargets(SET_RENDER_TARGETS_FLAG_VERIFY_STATES); + TransitionRenderTargets(RESOURCE_STATE_TRANSITION_MODE_VERIFY); #endif m_CommandBuffer.BeginRenderPass(m_RenderPass, m_Framebuffer, m_FramebufferWidth, m_FramebufferHeight); } } } - void DeviceContextVkImpl::SetRenderTargets( Uint32 NumRenderTargets, ITextureView *ppRenderTargets[], ITextureView *pDepthStencil, SET_RENDER_TARGETS_FLAGS Flags ) + void DeviceContextVkImpl::SetRenderTargets( Uint32 NumRenderTargets, + ITextureView* ppRenderTargets[], + ITextureView* pDepthStencil, + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode ) { if ( TDeviceContextBase::SetRenderTargets( NumRenderTargets, ppRenderTargets, pDepthStencil ) ) { @@ -1090,7 +1081,7 @@ namespace Diligent // CommitRenderPassAndFramebuffer() until draw call, otherwise we may have to // to end render pass and begin it again if we need to transition any resource // (for instance when CommitShaderResources() is called after SetRenderTargets()) - TransitionRenderTargets(Flags); + TransitionRenderTargets(StateTransitionMode); } void DeviceContextVkImpl::ResetRenderTargets() diff --git a/Graphics/GraphicsEngineVulkan/src/RenderDeviceFactoryVk.cpp b/Graphics/GraphicsEngineVulkan/src/RenderDeviceFactoryVk.cpp index 654e6bb1..12d46cef 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderDeviceFactoryVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderDeviceFactoryVk.cpp @@ -315,7 +315,7 @@ void EngineFactoryVkImpl::CreateSwapChainVk( IRenderDevice* pDevice, pDeviceContextVk->SetSwapChain(pSwapChainVk); // Bind default render target - pDeviceContextVk->SetRenderTargets( 0, nullptr, nullptr, SET_RENDER_TARGETS_FLAG_TRANSITION_ALL ); + pDeviceContextVk->SetRenderTargets( 0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION ); // Set default viewport pDeviceContextVk->SetViewports( 1, nullptr, 0, 0 ); diff --git a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp index ad68c9a0..e8fa7094 100644 --- a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp @@ -499,7 +499,7 @@ void SwapChainVkImpl::Present(Uint32 SyncInterval) { // If default framebuffer is bound, we need to call SetRenderTargets() // to bind new back buffer RTV - pImmediateCtxVk->SetRenderTargets(0, nullptr, nullptr, SET_RENDER_TARGETS_FLAG_TRANSITION_ALL); + pImmediateCtxVk->SetRenderTargets(0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); } } } @@ -551,7 +551,7 @@ void SwapChainVkImpl::Resize( Uint32 NewWidth, Uint32 NewHeight ) if( bIsDefaultFBBound ) { // Set default render target and viewport - pDeviceContext->SetRenderTargets( 0, nullptr, nullptr, SET_RENDER_TARGETS_FLAG_TRANSITION_ALL ); + pDeviceContext->SetRenderTargets( 0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); pDeviceContext->SetViewports( 1, nullptr, 0, 0 ); } } |
