From 812fc38d1b0957ed96d93e023b7322d65c5d3f5d Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 1 Aug 2020 18:18:48 -0700 Subject: Updated EndRenderPass to optionally update resource states --- .../GraphicsEngine/include/DeviceContextBase.hpp | 20 ++++++++++++++++++-- Graphics/GraphicsEngine/interface/DeviceContext.h | 9 ++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) (limited to 'Graphics/GraphicsEngine') diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.hpp b/Graphics/GraphicsEngine/include/DeviceContextBase.hpp index 9a9e5e89..68f9ec4e 100644 --- a/Graphics/GraphicsEngine/include/DeviceContextBase.hpp +++ b/Graphics/GraphicsEngine/include/DeviceContextBase.hpp @@ -130,7 +130,7 @@ public: virtual void DILIGENT_CALL_TYPE NextSubpass() override = 0; - virtual void DILIGENT_CALL_TYPE EndRenderPass() override = 0; + virtual void DILIGENT_CALL_TYPE EndRenderPass(bool UpdateResourceStates) override = 0; /// Base implementation of IDeviceContext::UpdateBuffer(); validates input parameters. virtual void DILIGENT_CALL_TYPE UpdateBuffer(IBuffer* pBuffer, @@ -902,9 +902,25 @@ inline void DeviceContextBase::NextSubpass( } template -inline void DeviceContextBase::EndRenderPass() +inline void DeviceContextBase::EndRenderPass(bool UpdateResourceStates) { VERIFY(m_pActiveRenderPass != nullptr, "There is no active render pass"); + VERIFY(m_pBoundFramebuffer != nullptr, "There is no active framebuffer"); + if (UpdateResourceStates) + { + const auto& RPDesc = m_pActiveRenderPass->GetDesc(); + const auto& FBDesc = m_pBoundFramebuffer->GetDesc(); + VERIFY(FBDesc.AttachmentCount >= RPDesc.AttachmentCount, + "Framebuffer attachment count (", FBDesc.AttachmentCount, ") is smaller than the render pass attachment count (", RPDesc.AttachmentCount, ")"); + for (Uint32 i = 0; i < RPDesc.AttachmentCount; ++i) + { + if (auto* pView = FBDesc.ppAttachments[i]) + { + auto* pTex = ValidatedCast(pView->GetTexture()); + pTex->SetState(RPDesc.pAttachments[i].FinalState); + } + } + } m_pActiveRenderPass.Release(); m_pBoundFramebuffer.Release(); m_SubpassIndex = 0; diff --git a/Graphics/GraphicsEngine/interface/DeviceContext.h b/Graphics/GraphicsEngine/interface/DeviceContext.h index 5b52cec0..3445a8d6 100644 --- a/Graphics/GraphicsEngine/interface/DeviceContext.h +++ b/Graphics/GraphicsEngine/interface/DeviceContext.h @@ -905,7 +905,14 @@ DILIGENT_BEGIN_INTERFACE(IDeviceContext, IObject) /// Ends current render pass. - VIRTUAL void METHOD(EndRenderPass)(THIS) PURE; + + /// \param [in] UpdateResourceStates - Indicates whether to update resource states so that they match + /// the final states specified by the render pass attachments. + /// Note that resources are always transitioned to the final states. + /// The flag only indicates if the internal state variables should be + /// updated to match the actual final states. + VIRTUAL void METHOD(EndRenderPass)(THIS_ + bool UpdateResourceStates) PURE; /// Executes a draw command. -- cgit v1.2.3