From 3aa36ab27691129b99702a4102f73afdd9f4c52b Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 1 Aug 2020 16:56:01 -0700 Subject: Fixed frame buffer attachment clear operations; updated clear render target tests --- .../GraphicsEngine/include/DeviceContextBase.hpp | 33 ++++++++++++++++++++++ Graphics/GraphicsEngine/interface/DeviceContext.h | 3 ++ 2 files changed, 36 insertions(+) (limited to 'Graphics/GraphicsEngine') diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.hpp b/Graphics/GraphicsEngine/include/DeviceContextBase.hpp index 8679f202..d217a115 100644 --- a/Graphics/GraphicsEngine/include/DeviceContextBase.hpp +++ b/Graphics/GraphicsEngine/include/DeviceContextBase.hpp @@ -855,10 +855,43 @@ inline void DeviceContextBase::BeginRenderP { VERIFY(m_pActiveRenderPass == nullptr, "Attempting to begin render pass while another render pass ('", m_pActiveRenderPass->GetDesc().Name, "') is active."); VERIFY(Attribs.pRenderPass != nullptr, "Render pass must not be null"); + VERIFY(Attribs.pFramebuffer != nullptr, "Framebuffer must not be null"); ResetRenderTargets(); + m_pActiveRenderPass = ValidatedCast(Attribs.pRenderPass); m_pBoundFramebuffer = ValidatedCast(Attribs.pFramebuffer); m_SubpassIndex = 0; + + const auto& FBDesc = m_pBoundFramebuffer->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(); + 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, ")"); + for (Uint32 i = 0; i < FBDesc.AttachmentCount; ++i) + { + auto* pView = FBDesc.ppAttachments[i]; + if (pView == nullptr) + return; + + auto* pTex = ValidatedCast(pView->GetTexture()); + auto RequiredState = RPDesc.pAttachments[i].InitialState; + if (Attribs.StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_TRANSITION) + { + StateTransitionDesc Barrier{pTex, RESOURCE_STATE_UNKNOWN, RequiredState, true}; + TransitionResourceStates(1, &Barrier); + } + else if (Attribs.StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY) + { + DvpVerifyTextureState(*pTex, RequiredState, "BeginRenderPass"); + } + } + } } template diff --git a/Graphics/GraphicsEngine/interface/DeviceContext.h b/Graphics/GraphicsEngine/interface/DeviceContext.h index 5eca22a9..5b52cec0 100644 --- a/Graphics/GraphicsEngine/interface/DeviceContext.h +++ b/Graphics/GraphicsEngine/interface/DeviceContext.h @@ -632,6 +632,9 @@ struct BeginRenderPassAttribs /// The array is indexed by attachment number. Only elements corresponding to cleared attachments are used. /// Other elements of pClearValues are ignored. OptimizedClearValue* pClearValues DEFAULT_INITIALIZER(nullptr); + + /// Framebuffer attachments state transition mode. + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_NONE); }; typedef struct BeginRenderPassAttribs BeginRenderPassAttribs; -- cgit v1.2.3