From 3ce2d21558fa0568ab7d332a5c300a661e444f44 Mon Sep 17 00:00:00 2001 From: assiduous Date: Tue, 4 Aug 2020 19:21:19 -0700 Subject: Added more renderpass-related checks --- .../GraphicsEngine/include/DeviceContextBase.hpp | 65 ++++++++++++++++------ 1 file changed, 47 insertions(+), 18 deletions(-) (limited to 'Graphics/GraphicsEngine') diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.hpp b/Graphics/GraphicsEngine/include/DeviceContextBase.hpp index 9e478675..c932d3b4 100644 --- a/Graphics/GraphicsEngine/include/DeviceContextBase.hpp +++ b/Graphics/GraphicsEngine/include/DeviceContextBase.hpp @@ -438,6 +438,9 @@ inline bool DeviceContextBase:: template inline void DeviceContextBase::InvalidateState() { + if (m_pActiveRenderPass != nullptr) + LOG_ERROR_MESSAGE("Invalidating context inside an active render pass. Call EndRenderPass() to finish the pass."); + DeviceContextBase::ClearStateCache(); } @@ -778,7 +781,7 @@ bool DeviceContextBase::CheckIfBoundAsDepth template bool DeviceContextBase::UnbindTextureFromFramebuffer(TextureImplType* pTexture, bool bShowMessage) { - VERIFY(m_pActiveRenderPass == nullptr, "State transitions are not allowed inside render pass"); + VERIFY(m_pActiveRenderPass == nullptr, "State transitions are not allowed inside a render pass."); if (pTexture == nullptr) return false; @@ -884,18 +887,18 @@ inline void DeviceContextBase::BeginRenderP ResetRenderTargets(); - m_pActiveRenderPass = ValidatedCast(Attribs.pRenderPass); - m_pBoundFramebuffer = ValidatedCast(Attribs.pFramebuffer); - m_SubpassIndex = 0; + auto* pNewRenderPass = ValidatedCast(Attribs.pRenderPass); + auto* pNewFramebuffer = ValidatedCast(Attribs.pFramebuffer); + m_SubpassIndex = 0; - const auto& FBDesc = m_pBoundFramebuffer->GetDesc(); + const auto& FBDesc = pNewFramebuffer->GetDesc(); m_FramebufferWidth = FBDesc.Width; m_FramebufferHeight = FBDesc.Height; m_FramebufferSlices = FBDesc.NumArraySlices; if (Attribs.StateTransitionMode != RESOURCE_STATE_TRANSITION_MODE_NONE) { - const auto& RPDesc = m_pActiveRenderPass->GetDesc(); + const auto& RPDesc = pNewRenderPass->GetDesc(); VERIFY(RPDesc.AttachmentCount <= FBDesc.AttachmentCount, "The number of attachments (", FBDesc.AttachmentCount, ") in currently bound framebuffer is smaller than the number of attachments in the render pass (", RPDesc.AttachmentCount, ")"); @@ -918,12 +921,17 @@ inline void DeviceContextBase::BeginRenderP } } } + + m_pActiveRenderPass = pNewRenderPass; + m_pBoundFramebuffer = pNewFramebuffer; + m_SubpassIndex = 0; } template inline void DeviceContextBase::NextSubpass() { VERIFY(m_pActiveRenderPass != nullptr, "There is no active render pass"); + VERIFY(m_SubpassIndex + 1 < m_pActiveRenderPass->GetDesc().SubpassCount, "The render pass has reached the final subpass already"); ++m_SubpassIndex; } @@ -932,6 +940,9 @@ inline void DeviceContextBase::EndRenderPas { VERIFY(m_pActiveRenderPass != nullptr, "There is no active render pass"); VERIFY(m_pBoundFramebuffer != nullptr, "There is no active framebuffer"); + VERIFY(m_pActiveRenderPass->GetDesc().SubpassCount == m_SubpassIndex + 1, + "Ending render pass at subpass ", m_SubpassIndex, " before reaching the final subpass"); + if (UpdateResourceStates) { const auto& RPDesc = m_pActiveRenderPass->GetDesc(); @@ -1247,7 +1258,7 @@ inline void DeviceContextBase:: UpdateTexture(ITexture* pTexture, Uint32 MipLevel, Uint32 Slice, const Box& DstBox, const TextureSubResData& SubresData, RESOURCE_STATE_TRANSITION_MODE SrcBufferTransitionMode, RESOURCE_STATE_TRANSITION_MODE TextureTransitionMode) { VERIFY(pTexture != nullptr, "pTexture must not be null"); - VERIFY(m_pActiveRenderPass == nullptr, "UpdateTexture must be used outside of render pass."); + VERIFY(m_pActiveRenderPass == nullptr, "UpdateTexture command must be used outside of render pass."); ValidateUpdateTextureParams(pTexture->GetDesc(), MipLevel, Slice, DstBox, SubresData); } @@ -1257,7 +1268,7 @@ inline void DeviceContextBase:: { VERIFY(CopyAttribs.pSrcTexture, "Src texture must not be null"); VERIFY(CopyAttribs.pDstTexture, "Dst texture must not be null"); - VERIFY(m_pActiveRenderPass == nullptr, "CopyTexture must be used outside of render pass."); + VERIFY(m_pActiveRenderPass == nullptr, "CopyTexture command must be used outside of render pass."); ValidateCopyTextureParams(CopyAttribs); } @@ -1289,7 +1300,7 @@ inline void DeviceContextBase:: GenerateMips(ITextureView* pTexView) { VERIFY(pTexView != nullptr, "pTexView must not be null"); - VERIFY(m_pActiveRenderPass == nullptr, "GenerateMips must be used outside of render pass."); + VERIFY(m_pActiveRenderPass == nullptr, "GenerateMips command must be used outside of render pass."); #ifdef DILIGENT_DEVELOPMENT { const auto& ViewDesc = pTexView->GetDesc(); @@ -1346,7 +1357,7 @@ void DeviceContextBase:: DEV_CHECK_ERR(!ResolveFmtAttribs.IsTypeless, "Format of a resolve operation must not be typeless when one of the texture formats is typeless"); } - VERIFY(m_pActiveRenderPass == nullptr, "ResolveTextureSubresource must be used outside of render pass."); + VERIFY(m_pActiveRenderPass == nullptr, "ResolveTextureSubresource command must be used outside of render pass."); #endif } @@ -1448,10 +1459,6 @@ inline bool DeviceContextBase:: pAttribsBuffer->GetDesc().Name, "' was not created with BIND_INDIRECT_DRAW_ARGS flag."); return false; } - - VERIFY(!(m_pActiveRenderPass != nullptr && Attribs.IndirectAttribsBufferStateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_TRANSITION), - "Resource state transitons are not allowed inside a render pass and may result in an undefined behavior. " - "Do not use RESOURCE_STATE_TRANSITION_MODE_TRANSITION or end the render pass first."); } else { @@ -1459,6 +1466,13 @@ inline bool DeviceContextBase:: return false; } + if (m_pActiveRenderPass != nullptr && Attribs.IndirectAttribsBufferStateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_TRANSITION) + { + LOG_ERROR_MESSAGE("Resource state transitons are not allowed inside a render pass and may result in an undefined behavior. " + "Do not use RESOURCE_STATE_TRANSITION_MODE_TRANSITION or end the render pass first."); + return false; + } + return true; } @@ -1503,10 +1517,6 @@ inline bool DeviceContextBase:: pAttribsBuffer->GetDesc().Name, "' was not created with BIND_INDIRECT_DRAW_ARGS flag."); return false; } - - VERIFY(!(m_pActiveRenderPass != nullptr && Attribs.IndirectAttribsBufferStateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_TRANSITION), - "Resource state transitons are not allowed inside a render pass and may result in an undefined behavior. " - "Do not use RESOURCE_STATE_TRANSITION_MODE_TRANSITION or end the render pass first."); } else { @@ -1514,6 +1524,13 @@ inline bool DeviceContextBase:: return false; } + if (m_pActiveRenderPass != nullptr && Attribs.IndirectAttribsBufferStateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_TRANSITION) + { + LOG_ERROR_MESSAGE("Resource state transitons are not allowed inside a render pass and may result in an undefined behavior. " + "Do not use RESOURCE_STATE_TRANSITION_MODE_TRANSITION or end the render pass first."); + return false; + } + return true; } @@ -1588,6 +1605,12 @@ inline bool DeviceContextBase:: return false; } + if (m_pActiveRenderPass != nullptr) + { + LOG_ERROR_MESSAGE("DispatchCompute command must be performed outside of render pass"); + return false; + } + if (Attribs.ThreadGroupCountX == 0) LOG_WARNING_MESSAGE("DispatchCompute command arguments are invalid: ThreadGroupCountX is zero."); @@ -1617,6 +1640,12 @@ inline bool DeviceContextBase:: return false; } + if (m_pActiveRenderPass != nullptr) + { + LOG_ERROR_MESSAGE("DispatchComputeIndirect command must be performed outside of render pass"); + return false; + } + if (pAttribsBuffer != nullptr) { if ((pAttribsBuffer->GetDesc().BindFlags & BIND_INDIRECT_DRAW_ARGS) == 0) -- cgit v1.2.3