From cbc82d73874ea1422c295d44246138a820664e91 Mon Sep 17 00:00:00 2001 From: assiduous Date: Thu, 4 Mar 2021 20:30:35 -0800 Subject: Moved static variable cache and managers to PipelineResourceSignatureBase --- .../include/EngineGLImplTraits.hpp | 6 ++ .../include/PipelineResourceSignatureGLImpl.hpp | 5 -- .../include/ShaderVariableGL.hpp | 2 +- .../src/PipelineResourceSignatureGLImpl.cpp | 70 +++++----------------- .../src/ShaderResourceBindingGLImpl.cpp | 2 +- .../GraphicsEngineOpenGL/src/ShaderVariableGL.cpp | 4 +- 6 files changed, 25 insertions(+), 64 deletions(-) (limited to 'Graphics/GraphicsEngineOpenGL') diff --git a/Graphics/GraphicsEngineOpenGL/include/EngineGLImplTraits.hpp b/Graphics/GraphicsEngineOpenGL/include/EngineGLImplTraits.hpp index 077c11ce..8bc1da77 100644 --- a/Graphics/GraphicsEngineOpenGL/include/EngineGLImplTraits.hpp +++ b/Graphics/GraphicsEngineOpenGL/include/EngineGLImplTraits.hpp @@ -71,6 +71,9 @@ class PipelineResourceSignatureGLImpl; class FixedBlockMemoryAllocator; +class ShaderResourceCacheGL; +class ShaderVariableManagerGL; + struct EngineGLImplTraits { using RenderDeviceInterface = IGLDeviceBaseInterface; @@ -110,6 +113,9 @@ struct EngineGLImplTraits using BuffViewObjAllocatorType = FixedBlockMemoryAllocator; using TexViewObjAllocatorType = FixedBlockMemoryAllocator; + + using ShaderResourceCacheImplType = ShaderResourceCacheGL; + using ShaderVariableManagerImplType = ShaderVariableManagerGL; }; } // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/PipelineResourceSignatureGLImpl.hpp b/Graphics/GraphicsEngineOpenGL/include/PipelineResourceSignatureGLImpl.hpp index 1966c12d..a1a0de52 100644 --- a/Graphics/GraphicsEngineOpenGL/include/PipelineResourceSignatureGLImpl.hpp +++ b/Graphics/GraphicsEngineOpenGL/include/PipelineResourceSignatureGLImpl.hpp @@ -214,11 +214,6 @@ private: ResourceAttribs* m_pResourceAttribs = nullptr; // [m_Desc.NumResources] - // Resource cache for static resource variables only - ShaderResourceCacheGL* m_pStaticResCache = nullptr; - - ShaderVariableManagerGL* m_StaticVarsMgrs = nullptr; // [GetNumStaticResStages()] - using SamplerPtr = RefCntAutoPtr; SamplerPtr* m_ImmutableSamplers = nullptr; // [m_Desc.NumImmutableSamplers] diff --git a/Graphics/GraphicsEngineOpenGL/include/ShaderVariableGL.hpp b/Graphics/GraphicsEngineOpenGL/include/ShaderVariableGL.hpp index f03d3c2a..944977a5 100644 --- a/Graphics/GraphicsEngineOpenGL/include/ShaderVariableGL.hpp +++ b/Graphics/GraphicsEngineOpenGL/include/ShaderVariableGL.hpp @@ -88,7 +88,7 @@ public: ~ShaderVariableManagerGL(); - void DestroyVariables(IMemoryAllocator& Allocator); + void Destroy(IMemoryAllocator& Allocator); // No copies, only moves are allowed // clang-format off diff --git a/Graphics/GraphicsEngineOpenGL/src/PipelineResourceSignatureGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/PipelineResourceSignatureGLImpl.cpp index 07f97f3d..10572df9 100644 --- a/Graphics/GraphicsEngineOpenGL/src/PipelineResourceSignatureGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/PipelineResourceSignatureGLImpl.cpp @@ -130,35 +130,20 @@ PipelineResourceSignatureGLImpl::PipelineResourceSignatureGLImpl(IReferenceCount { try { - FixedLinearAllocator MemPool{GetRawAllocator()}; - - // Reserve at least 1 element because m_pResourceAttribs must hold a pointer to memory - MemPool.AddSpace(std::max(1u, Desc.NumResources)); - MemPool.AddSpace(Desc.NumImmutableSamplers); - - ReserveSpaceForDescription(MemPool, Desc); - - const auto NumStaticResStages = GetNumStaticResStages(); - if (NumStaticResStages > 0) - { - MemPool.AddSpace(1); - MemPool.AddSpace(NumStaticResStages); - } - - MemPool.Reserve(); + auto& RawAllocator{GetRawAllocator()}; + auto MemPool = ReserveSpace(RawAllocator, Desc, + [&](FixedLinearAllocator& MemPool) // + { + MemPool.AddSpace(Desc.NumResources); + MemPool.AddSpace(Desc.NumImmutableSamplers); + }); static_assert(std::is_trivially_destructible::value, "ResourceAttribs objects must be constructed to be properly destructed in case an excpetion is thrown"); - m_pResourceAttribs = MemPool.Allocate(std::max(1u, m_Desc.NumResources)); + m_pResourceAttribs = MemPool.Allocate(m_Desc.NumResources); m_ImmutableSamplers = MemPool.ConstructArray(m_Desc.NumImmutableSamplers); - // The memory is now owned by PipelineResourceSignatureGLImpl and will be freed by Destruct(). - auto* Ptr = MemPool.ReleaseOwnership(); - VERIFY_EXPR(Ptr == m_pResourceAttribs); - (void)Ptr; - - CopyDescription(MemPool, Desc); - + const auto NumStaticResStages = GetNumStaticResStages(); if (NumStaticResStages > 0) { m_pStaticResCache = MemPool.Construct(ShaderResourceCacheGL::CacheContentType::Signature); @@ -177,7 +162,7 @@ PipelineResourceSignatureGLImpl::PipelineResourceSignatureGLImpl(IReferenceCount { VERIFY_EXPR(static_cast(Idx) < NumStaticResStages); const auto ShaderType = GetShaderTypeFromPipelineIndex(i, GetPipelineType()); - m_StaticVarsMgrs[Idx].Initialize(*this, GetRawAllocator(), AllowedVarTypes, _countof(AllowedVarTypes), ShaderType); + m_StaticVarsMgrs[Idx].Initialize(*this, RawAllocator, AllowedVarTypes, _countof(AllowedVarTypes), ShaderType); } } } @@ -325,8 +310,6 @@ PipelineResourceSignatureGLImpl::~PipelineResourceSignatureGLImpl() void PipelineResourceSignatureGLImpl::Destruct() { - auto& RawAllocator = GetRawAllocator(); - if (m_ImmutableSamplers != nullptr) { for (Uint32 s = 0; s < m_Desc.NumImmutableSamplers; ++s) @@ -335,30 +318,7 @@ void PipelineResourceSignatureGLImpl::Destruct() m_ImmutableSamplers = nullptr; } - if (m_StaticVarsMgrs) - { - for (auto Idx : m_StaticResStageIndex) - { - if (Idx >= 0) - { - m_StaticVarsMgrs[Idx].DestroyVariables(RawAllocator); - m_StaticVarsMgrs[Idx].~ShaderVariableManagerGL(); - } - } - m_StaticVarsMgrs = nullptr; - } - - if (m_pStaticResCache) - { - m_pStaticResCache->~ShaderResourceCacheGL(); - m_pStaticResCache = nullptr; - } - - if (void* pRawMem = m_pResourceAttribs) - { - RawAllocator.Free(pRawMem); - m_pResourceAttribs = nullptr; - } + m_pResourceAttribs = nullptr; TPipelineResourceSignatureBase::Destruct(); } @@ -519,24 +479,24 @@ void PipelineResourceSignatureGLImpl::InitializeStaticSRBResources(IShaderResour Uint32 PipelineResourceSignatureGLImpl::GetStaticVariableCount(SHADER_TYPE ShaderType) const { - return GetStaticVariableCountImpl(ShaderType, m_StaticVarsMgrs); + return GetStaticVariableCountImpl(ShaderType); } IShaderResourceVariable* PipelineResourceSignatureGLImpl::GetStaticVariableByName(SHADER_TYPE ShaderType, const Char* Name) { - return GetStaticVariableByNameImpl(ShaderType, Name, m_StaticVarsMgrs); + return GetStaticVariableByNameImpl(ShaderType, Name); } IShaderResourceVariable* PipelineResourceSignatureGLImpl::GetStaticVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) { - return GetStaticVariableByIndexImpl(ShaderType, Index, m_StaticVarsMgrs); + return GetStaticVariableByIndexImpl(ShaderType, Index); } void PipelineResourceSignatureGLImpl::BindStaticResources(Uint32 ShaderFlags, IResourceMapping* pResMapping, Uint32 Flags) { - BindStaticResourcesImpl(ShaderFlags, pResMapping, Flags, m_StaticVarsMgrs); + BindStaticResourcesImpl(ShaderFlags, pResMapping, Flags); } void PipelineResourceSignatureGLImpl::CopyStaticResources(ShaderResourceCacheGL& DstResourceCache) const diff --git a/Graphics/GraphicsEngineOpenGL/src/ShaderResourceBindingGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/ShaderResourceBindingGLImpl.cpp index 637dcb6d..515331de 100644 --- a/Graphics/GraphicsEngineOpenGL/src/ShaderResourceBindingGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/ShaderResourceBindingGLImpl.cpp @@ -104,7 +104,7 @@ void ShaderResourceBindingGLImpl::Destruct() for (Uint32 s = 0; s < GetNumShaders(); ++s) { auto& VarDataAllocator = SRBMemAllocator.GetShaderVariableDataAllocator(s); - m_pShaderVarMgrs[s].DestroyVariables(VarDataAllocator); + m_pShaderVarMgrs[s].Destroy(VarDataAllocator); m_pShaderVarMgrs[s].~ShaderVariableManagerGL(); } diff --git a/Graphics/GraphicsEngineOpenGL/src/ShaderVariableGL.cpp b/Graphics/GraphicsEngineOpenGL/src/ShaderVariableGL.cpp index be2312de..91a2fa88 100644 --- a/Graphics/GraphicsEngineOpenGL/src/ShaderVariableGL.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/ShaderVariableGL.cpp @@ -199,10 +199,10 @@ void ShaderVariableManagerGL::Initialize(const PipelineResourceSignatureGLImpl& ShaderVariableManagerGL::~ShaderVariableManagerGL() { - VERIFY(m_ResourceBuffer == nullptr, "DestroyVariables() has not been called"); + VERIFY(m_ResourceBuffer == nullptr, "Destroy() has not been called"); } -void ShaderVariableManagerGL::DestroyVariables(IMemoryAllocator& Allocator) +void ShaderVariableManagerGL::Destroy(IMemoryAllocator& Allocator) { if (m_ResourceBuffer == nullptr) return; -- cgit v1.2.3