From b455f877b27282b3235a26afdd78207ce48c8615 Mon Sep 17 00:00:00 2001 From: assiduous Date: Fri, 20 Nov 2020 20:17:45 -0800 Subject: DeviceContextBase: added m_FramebufferSamples member --- .../GraphicsEngine/include/DeviceContextBase.hpp | 49 +++++++++++++++++----- 1 file changed, 38 insertions(+), 11 deletions(-) (limited to 'Graphics/GraphicsEngine') diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.hpp b/Graphics/GraphicsEngine/include/DeviceContextBase.hpp index 4eebd683..ac56eac9 100644 --- a/Graphics/GraphicsEngine/include/DeviceContextBase.hpp +++ b/Graphics/GraphicsEngine/include/DeviceContextBase.hpp @@ -322,6 +322,8 @@ protected: Uint32 m_FramebufferHeight = 0; /// Number of array slices in the currently bound framebuffer Uint32 m_FramebufferSlices = 0; + /// Number of samples in the currently bound framebuffer + Uint32 m_FramebufferSamples = 0; /// Strong references to the bound depth stencil view. /// Use final texture view implementation type to avoid virtual calls to AddRef()/Release() @@ -598,6 +600,7 @@ inline bool DeviceContextBase:: m_FramebufferWidth = 0; m_FramebufferHeight = 0; m_FramebufferSlices = 0; + m_FramebufferSamples = 0; if (NumRenderTargets != m_NumBoundRenderTargets) { @@ -621,11 +624,12 @@ inline bool DeviceContextBase:: // Use this RTV to set the render target size if (m_FramebufferWidth == 0) { - auto* pTex = pRTView->GetTexture(); - const auto& TexDesc = pTex->GetDesc(); - m_FramebufferWidth = std::max(TexDesc.Width >> RTVDesc.MostDetailedMip, 1U); - m_FramebufferHeight = std::max(TexDesc.Height >> RTVDesc.MostDetailedMip, 1U); - m_FramebufferSlices = RTVDesc.NumArraySlices; + auto* pTex = pRTView->GetTexture(); + const auto& TexDesc = pTex->GetDesc(); + m_FramebufferWidth = std::max(TexDesc.Width >> RTVDesc.MostDetailedMip, 1U); + m_FramebufferHeight = std::max(TexDesc.Height >> RTVDesc.MostDetailedMip, 1U); + m_FramebufferSlices = RTVDesc.NumArraySlices; + m_FramebufferSamples = TexDesc.SampleCount; } else { @@ -637,6 +641,8 @@ inline bool DeviceContextBase:: LOG_ERROR_MESSAGE("Render target height (", std::max(TexDesc.Height >> RTVDesc.MostDetailedMip, 1U), ") specified by RTV '", RTVDesc.Name, "' is inconsistent with the height of previously bound render targets (", m_FramebufferHeight, ")"); if (m_FramebufferSlices != RTVDesc.NumArraySlices) LOG_ERROR_MESSAGE("Number of slices (", RTVDesc.NumArraySlices, ") specified by RTV '", RTVDesc.Name, "' is inconsistent with the number of slices in previously bound render targets (", m_FramebufferSlices, ")"); + if (m_FramebufferSamples != TexDesc.SampleCount) + LOG_ERROR_MESSAGE("Sample count (", TexDesc.SampleCount, ") of RTV '", RTVDesc.Name, "' is inconsistent with the sample count of previously bound render targets (", m_FramebufferSamples, ")"); #endif } } @@ -662,11 +668,12 @@ inline bool DeviceContextBase:: // Use depth stencil size to set render target size if (m_FramebufferWidth == 0) { - auto* pTex = pDepthStencil->GetTexture(); - const auto& TexDesc = pTex->GetDesc(); - m_FramebufferWidth = std::max(TexDesc.Width >> DSVDesc.MostDetailedMip, 1U); - m_FramebufferHeight = std::max(TexDesc.Height >> DSVDesc.MostDetailedMip, 1U); - m_FramebufferSlices = DSVDesc.NumArraySlices; + auto* pTex = pDepthStencil->GetTexture(); + const auto& TexDesc = pTex->GetDesc(); + m_FramebufferWidth = std::max(TexDesc.Width >> DSVDesc.MostDetailedMip, 1U); + m_FramebufferHeight = std::max(TexDesc.Height >> DSVDesc.MostDetailedMip, 1U); + m_FramebufferSlices = DSVDesc.NumArraySlices; + m_FramebufferSamples = TexDesc.SampleCount; } else { @@ -678,6 +685,8 @@ inline bool DeviceContextBase:: LOG_ERROR_MESSAGE("Depth-stencil target height (", std::max(TexDesc.Height >> DSVDesc.MostDetailedMip, 1U), ") specified by DSV '", DSVDesc.Name, "' is inconsistent with the height of previously bound render targets (", m_FramebufferHeight, ")"); if (m_FramebufferSlices != DSVDesc.NumArraySlices) LOG_ERROR_MESSAGE("Number of slices (", DSVDesc.NumArraySlices, ") specified by DSV '", DSVDesc.Name, "' is inconsistent with the number of slices in previously bound render targets (", m_FramebufferSlices, ")"); + if (m_FramebufferSamples != TexDesc.SampleCount) + LOG_ERROR_MESSAGE("Sample count (", TexDesc.SampleCount, ") of DSV '", DSVDesc.Name, "' is inconsistent with the sample count of previously bound render targets (", m_FramebufferSamples, ")"); #endif } } @@ -689,7 +698,7 @@ inline bool DeviceContextBase:: } - VERIFY_EXPR(m_FramebufferWidth > 0 && m_FramebufferHeight > 0 && m_FramebufferSlices > 0); + VERIFY_EXPR(m_FramebufferWidth > 0 && m_FramebufferHeight > 0 && m_FramebufferSlices > 0 && m_FramebufferSamples > 0); return bBindRenderTargets; } @@ -705,6 +714,8 @@ inline bool DeviceContextBase::SetSubpassRe VERIFY_EXPR(m_SubpassIndex < RPDesc.SubpassCount); const auto& Subpass = RPDesc.pSubpasses[m_SubpassIndex]; + m_FramebufferSamples = 0; + ITextureView* ppRTVs[MAX_RENDER_TARGETS] = {}; ITextureView* pDSV = nullptr; for (Uint32 rt = 0; rt < Subpass.RenderTargetAttachmentCount; ++rt) @@ -714,6 +725,13 @@ inline bool DeviceContextBase::SetSubpassRe { VERIFY_EXPR(RTAttachmentRef.AttachmentIndex < RPDesc.AttachmentCount); ppRTVs[rt] = FBDesc.ppAttachments[RTAttachmentRef.AttachmentIndex]; + if (ppRTVs[rt] != nullptr) + { + if (m_FramebufferSamples == 0) + m_FramebufferSamples = ppRTVs[rt]->GetTexture()->GetDesc().SampleCount; + else + DEV_CHECK_ERR(m_FramebufferSamples == ppRTVs[rt]->GetTexture()->GetDesc().SampleCount, "Inconsistent sample count"); + } } } @@ -724,6 +742,13 @@ inline bool DeviceContextBase::SetSubpassRe { VERIFY_EXPR(DSAttachmentRef.AttachmentIndex < RPDesc.AttachmentCount); pDSV = FBDesc.ppAttachments[DSAttachmentRef.AttachmentIndex]; + if (pDSV != nullptr) + { + if (m_FramebufferSamples == 0) + m_FramebufferSamples = pDSV->GetTexture()->GetDesc().SampleCount; + else + DEV_CHECK_ERR(m_FramebufferSamples == pDSV->GetTexture()->GetDesc().SampleCount, "Inconsistent sample count"); + } } } bool BindRenderTargets = SetRenderTargets(Subpass.RenderTargetAttachmentCount, ppRTVs, pDSV); @@ -732,6 +757,7 @@ inline bool DeviceContextBase::SetSubpassRe m_FramebufferWidth = FBDesc.Width; m_FramebufferHeight = FBDesc.Height; m_FramebufferSlices = FBDesc.NumArraySlices; + VERIFY_EXPR(m_FramebufferSamples > 0); return BindRenderTargets; } @@ -905,6 +931,7 @@ void DeviceContextBase::ResetRenderTargets( m_FramebufferWidth = 0; m_FramebufferHeight = 0; m_FramebufferSlices = 0; + m_FramebufferSamples = 0; m_pBoundDepthStencil.Release(); -- cgit v1.2.3 From 39852e8b8bdc08b65a1b9baabbe7e2167eae5fdb Mon Sep 17 00:00:00 2001 From: assiduous Date: Sun, 22 Nov 2020 13:33:34 -0800 Subject: Removed autorelease pool from unit tests: Metal backend now catches all autoreleased objects automatically --- Graphics/GraphicsEngine/interface/BlendState.h | 3 +++ Graphics/GraphicsEngine/interface/GraphicsTypes.h | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) (limited to 'Graphics/GraphicsEngine') diff --git a/Graphics/GraphicsEngine/interface/BlendState.h b/Graphics/GraphicsEngine/interface/BlendState.h index 2dd843ec..50feb22c 100644 --- a/Graphics/GraphicsEngine/interface/BlendState.h +++ b/Graphics/GraphicsEngine/interface/BlendState.h @@ -171,6 +171,9 @@ DILIGENT_TYPED_ENUM(BLEND_OPERATION, Int8) /// writable components of the render target DILIGENT_TYPED_ENUM(COLOR_MASK, Int8) { + /// Do not store any components. + COLOR_MASK_NONE = 0, + /// Allow data to be stored in the red component. COLOR_MASK_RED = 1, diff --git a/Graphics/GraphicsEngine/interface/GraphicsTypes.h b/Graphics/GraphicsEngine/interface/GraphicsTypes.h index d85540ac..41fd8210 100644 --- a/Graphics/GraphicsEngine/interface/GraphicsTypes.h +++ b/Graphics/GraphicsEngine/interface/GraphicsTypes.h @@ -2258,6 +2258,25 @@ struct EngineMtlCreateInfo DILIGENT_DERIVE(EngineCreateInfo) /// resource manager and then suballocate from this chunk in a lock-free /// fashion. DynamicHeapPageSize defines the size of this chunk. Uint32 DynamicHeapPageSize DEFAULT_INITIALIZER(4 << 20); + + + /// Indicates if device contexts should automatically manage autorelease pools. + + /// Metal API creates a lot of autoreleased objects. By default, the engine + /// will catch all these objects by pushing autorelease pools where necessary. + /// When UseAutoreleasePoolsInContexts is set to false, the engine will not use + /// autorelease pools in device contexts and the application will be responsible + /// for ensuring that all context commands are issued from within an autorelease + /// pool to avoid memory leaks. + /// + /// \note Autorelease pool is pushed by the first command of the device context + /// that needs it and popped by IDeviceContext::FinishFrame(). + /// The method must always be called from the same thread that + /// issued the context commands. + /// + /// Creating device objects will not leak memory even when + /// UseAutoreleasePoolsInContexts is set to false. + bool UseAutoreleasePoolsInContexts DEFAULT_INITIALIZER(true); }; typedef struct EngineMtlCreateInfo EngineMtlCreateInfo; -- cgit v1.2.3