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 ++++++++- .../include/DeviceContextD3D11Impl.hpp | 2 +- .../src/DeviceContextD3D11Impl.cpp | 4 ++-- .../include/DeviceContextD3D12Impl.hpp | 2 +- .../src/DeviceContextD3D12Impl.cpp | 4 ++-- .../include/DeviceContextMtlImpl.h | 2 +- .../GraphicsEngineMetal/src/DeviceContextMtlImpl.mm | 4 ++-- .../include/DeviceContextGLImpl.hpp | 2 +- .../GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp | 4 ++-- .../include/DeviceContextVkImpl.hpp | 2 +- .../GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp | 4 ++-- 12 files changed, 41 insertions(+), 18 deletions(-) (limited to 'Graphics') 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. diff --git a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.hpp b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.hpp index 7f148d8c..9df79314 100644 --- a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.hpp +++ b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.hpp @@ -131,7 +131,7 @@ public: virtual void DILIGENT_CALL_TYPE NextSubpass() override final; /// Implementation of IDeviceContext::EndRenderPass() in Direct3D11 backend. - virtual void DILIGENT_CALL_TYPE EndRenderPass() override final; + virtual void DILIGENT_CALL_TYPE EndRenderPass(bool UpdateResourceStates) override final; /// Implementation of IDeviceContext::Draw() in Direct3D11 backend. virtual void DILIGENT_CALL_TYPE Draw(const DrawAttribs& Attribs) override final; diff --git a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp index 339e6f35..857ed7c5 100755 --- a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp @@ -1629,9 +1629,9 @@ void DeviceContextD3D11Impl::NextSubpass() UNEXPECTED("Method not implemented"); } -void DeviceContextD3D11Impl::EndRenderPass() +void DeviceContextD3D11Impl::EndRenderPass(bool UpdateResourceStates) { - TDeviceContextBase::EndRenderPass(); + TDeviceContextBase::EndRenderPass(UpdateResourceStates); UNEXPECTED("Method not implemented"); } diff --git a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.hpp index 28f336d4..eea40064 100644 --- a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.hpp @@ -131,7 +131,7 @@ public: virtual void DILIGENT_CALL_TYPE NextSubpass() override final; /// Implementation of IDeviceContext::EndRenderPass() in Direct3D11 backend. - virtual void DILIGENT_CALL_TYPE EndRenderPass() override final; + virtual void DILIGENT_CALL_TYPE EndRenderPass(bool UpdateResourceStates) override final; // clang-format off /// Implementation of IDeviceContext::Draw() in Direct3D12 backend. diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp index 6a6739f0..4ab5455d 100644 --- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp @@ -981,9 +981,9 @@ void DeviceContextD3D12Impl::NextSubpass() UNEXPECTED("Method not implemented"); } -void DeviceContextD3D12Impl::EndRenderPass() +void DeviceContextD3D12Impl::EndRenderPass(bool UpdateResourceStates) { - TDeviceContextBase::EndRenderPass(); + TDeviceContextBase::EndRenderPass(UpdateResourceStates); UNEXPECTED("Method not implemented"); } diff --git a/Graphics/GraphicsEngineMetal/include/DeviceContextMtlImpl.h b/Graphics/GraphicsEngineMetal/include/DeviceContextMtlImpl.h index 0bfff2b3..b5a7feec 100644 --- a/Graphics/GraphicsEngineMetal/include/DeviceContextMtlImpl.h +++ b/Graphics/GraphicsEngineMetal/include/DeviceContextMtlImpl.h @@ -100,7 +100,7 @@ public: virtual void NextSubpass() override final; - virtual void EndRenderPass() override final; + virtual void EndRenderPass(bool UpdateResourceStates) override final; virtual void Draw(const DrawAttribs& Attribs) override final; virtual void DrawIndexed(const DrawIndexedAttribs& Attribs) override final; diff --git a/Graphics/GraphicsEngineMetal/src/DeviceContextMtlImpl.mm b/Graphics/GraphicsEngineMetal/src/DeviceContextMtlImpl.mm index abfa15ba..ff08c1bb 100644 --- a/Graphics/GraphicsEngineMetal/src/DeviceContextMtlImpl.mm +++ b/Graphics/GraphicsEngineMetal/src/DeviceContextMtlImpl.mm @@ -383,9 +383,9 @@ namespace Diligent LOG_ERROR_MESSAGE("DeviceContextMtlImpl::NextSubpass() is not implemented"); } - void DeviceContextMtlImpl::EndRenderPass() + void DeviceContextMtlImpl::EndRenderPass(bool UpdateResourceStates) { - TDeviceContextBase::EndRenderPass(); + TDeviceContextBase::EndRenderPass(UpdateResourceStates); LOG_ERROR_MESSAGE("DeviceContextMtlImpl::EndRenderPass() is not implemented"); } diff --git a/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.hpp b/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.hpp index ad9ff03b..52b3481b 100644 --- a/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.hpp +++ b/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.hpp @@ -121,7 +121,7 @@ public: virtual void DILIGENT_CALL_TYPE NextSubpass() override final; /// Implementation of IDeviceContext::EndRenderPass() in Direct3D11 backend. - virtual void DILIGENT_CALL_TYPE EndRenderPass() override final; + virtual void DILIGENT_CALL_TYPE EndRenderPass(bool UpdateResourceStates) override final; // clang-format off diff --git a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp index c585137b..d1df47e3 100644 --- a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp @@ -415,9 +415,9 @@ void DeviceContextGLImpl::NextSubpass() UNEXPECTED("Method not implemented"); } -void DeviceContextGLImpl::EndRenderPass() +void DeviceContextGLImpl::EndRenderPass(bool UpdateResourceStates) { - TDeviceContextBase::EndRenderPass(); + TDeviceContextBase::EndRenderPass(UpdateResourceStates); UNEXPECTED("Method not implemented"); } diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp index ebca0282..a0249ec9 100644 --- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp @@ -142,7 +142,7 @@ public: virtual void DILIGENT_CALL_TYPE NextSubpass() override final; /// Implementation of IDeviceContext::EndRenderPass() in Direct3D11 backend. - virtual void DILIGENT_CALL_TYPE EndRenderPass() override final; + virtual void DILIGENT_CALL_TYPE EndRenderPass(bool UpdateResourceStates) override final; // clang-format off /// Implementation of IDeviceContext::Draw() in Vulkan backend. diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index d15f5720..0eb778f0 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -1307,9 +1307,9 @@ void DeviceContextVkImpl::NextSubpass() m_CommandBuffer.NextSubpass(); } -void DeviceContextVkImpl::EndRenderPass() +void DeviceContextVkImpl::EndRenderPass(bool UpdateResourceStates) { - TDeviceContextBase::EndRenderPass(); + TDeviceContextBase::EndRenderPass(UpdateResourceStates); m_CommandBuffer.EndRenderPass(); } -- cgit v1.2.3