From e70a221012b367b17d5723df0ab01834a221e544 Mon Sep 17 00:00:00 2001 From: assiduous Date: Mon, 10 Aug 2020 23:45:43 -0700 Subject: OpenGL backend: added required memory barriers for framebuffer attachments --- .../src/DeviceContextGLImpl.cpp | 38 +++++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'Graphics/GraphicsEngineOpenGL') diff --git a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp index 3b3122bf..4650e9de 100644 --- a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp @@ -445,26 +445,46 @@ void DeviceContextGLImpl::BeginSubpass() const auto& RTAttachmentRef = SubpassDesc.pRenderTargetAttachments[rt]; if (RTAttachmentRef.AttachmentIndex != ATTACHMENT_UNUSED) { + auto* const pRTV = ValidatedCast(FBDesc.ppAttachments[RTAttachmentRef.AttachmentIndex]); + if (pRTV == nullptr) + continue; + + auto* const pColorTexGL = pRTV->GetTexture(); + pColorTexGL->TextureMemoryBarrier( + GL_FRAMEBUFFER_BARRIER_BIT, // Reads and writes via framebuffer object attachments after the + // barrier will reflect data written by shaders prior to the barrier. + // Additionally, framebuffer writes issued after the barrier will wait + // on the completion of all shader writes issued prior to the barrier. + m_ContextState); + const auto& AttachmentDesc = RPDesc.pAttachments[RTAttachmentRef.AttachmentIndex]; auto FirstLastUse = m_pActiveRenderPass->GetAttachmentFirstLastUse(RTAttachmentRef.AttachmentIndex); if (FirstLastUse.first == m_SubpassIndex && AttachmentDesc.LoadOp == ATTACHMENT_LOAD_OP_CLEAR) { - auto* pRTV = FBDesc.ppAttachments[RTAttachmentRef.AttachmentIndex]; ClearRenderTarget(pRTV, m_AttachmentClearValues[RTAttachmentRef.AttachmentIndex].Color, RESOURCE_STATE_TRANSITION_MODE_NONE); } } } - if (SubpassDesc.pDepthStencilAttachment != nullptr && SubpassDesc.pDepthStencilAttachment->AttachmentIndex != ATTACHMENT_UNUSED) + if (SubpassDesc.pDepthStencilAttachment != nullptr) { - auto DepthAttachmentIndex = SubpassDesc.pDepthStencilAttachment->AttachmentIndex; - const auto& AttachmentDesc = RPDesc.pAttachments[DepthAttachmentIndex]; - auto FirstLastUse = m_pActiveRenderPass->GetAttachmentFirstLastUse(DepthAttachmentIndex); - if (FirstLastUse.first == m_SubpassIndex && AttachmentDesc.LoadOp == ATTACHMENT_LOAD_OP_CLEAR) + const auto DepthAttachmentIndex = SubpassDesc.pDepthStencilAttachment->AttachmentIndex; + if (DepthAttachmentIndex != ATTACHMENT_UNUSED) { - auto* pDSV = FBDesc.ppAttachments[DepthAttachmentIndex]; - const auto& ClearVal = m_AttachmentClearValues[DepthAttachmentIndex].DepthStencil; - ClearDepthStencil(pDSV, CLEAR_DEPTH_FLAG | CLEAR_STENCIL_FLAG, ClearVal.Depth, ClearVal.Stencil, RESOURCE_STATE_TRANSITION_MODE_NONE); + auto* const pDSV = ValidatedCast(FBDesc.ppAttachments[DepthAttachmentIndex]); + if (pDSV != nullptr) + { + auto* pDepthTexGL = pDSV->GetTexture(); + pDepthTexGL->TextureMemoryBarrier(GL_FRAMEBUFFER_BARRIER_BIT, m_ContextState); + + const auto& AttachmentDesc = RPDesc.pAttachments[DepthAttachmentIndex]; + auto FirstLastUse = m_pActiveRenderPass->GetAttachmentFirstLastUse(DepthAttachmentIndex); + if (FirstLastUse.first == m_SubpassIndex && AttachmentDesc.LoadOp == ATTACHMENT_LOAD_OP_CLEAR) + { + const auto& ClearVal = m_AttachmentClearValues[DepthAttachmentIndex].DepthStencil; + ClearDepthStencil(pDSV, CLEAR_DEPTH_FLAG | CLEAR_STENCIL_FLAG, ClearVal.Depth, ClearVal.Stencil, RESOURCE_STATE_TRANSITION_MODE_NONE); + } + } } } } -- cgit v1.2.3