From 1dfd5042779a493285c397d46f8d903d67c9f972 Mon Sep 17 00:00:00 2001 From: assiduous Date: Mon, 8 Mar 2021 10:27:35 -0800 Subject: Resource singature: moved allocation of static resource cache and var managers to PipelineResourceSignatureBase --- .../include/PipelineResourceSignatureBase.hpp | 57 ++++++++++++++-------- .../include/ShaderResourceBindingBase.hpp | 3 -- .../src/PipelineResourceSignatureD3D12Impl.cpp | 17 +++---- .../src/PipelineResourceSignatureGLImpl.cpp | 20 +++----- .../src/PipelineResourceSignatureVkImpl.cpp | 15 +++--- 5 files changed, 55 insertions(+), 57 deletions(-) (limited to 'Graphics') diff --git a/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp b/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp index c2e407ee..db5cb061 100644 --- a/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp +++ b/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp @@ -44,6 +44,7 @@ #include "StringTools.hpp" #include "PlatformMisc.hpp" #include "SRBMemoryAllocator.hpp" +#include "ShaderResourceCacheCommon.hpp" namespace Diligent { @@ -377,12 +378,44 @@ public: protected: template - FixedLinearAllocator ReserveSpace(IMemoryAllocator& RawAllocator, - const PipelineResourceSignatureDesc& Desc, - TReserveCustomData ReserveCustomData) noexcept(false) + FixedLinearAllocator AllocateInternalObjects(IMemoryAllocator& RawAllocator, + const PipelineResourceSignatureDesc& Desc, + TReserveCustomData ReserveCustomData) noexcept(false) { FixedLinearAllocator Allocator{RawAllocator}; + ReserveSpaceForDescription(Allocator, Desc); + + const auto NumStaticResStages = GetNumStaticResStages(); + if (NumStaticResStages > 0) + { + Allocator.AddSpace(1); + Allocator.AddSpace(NumStaticResStages); + } + + ReserveCustomData(Allocator); + + Allocator.Reserve(); + // The memory is now owned by PipelineResourceSignatureBase and will be freed by Destruct(). + m_pRawMemory = decltype(m_pRawMemory){Allocator.ReleaseOwnership(), STDDeleterRawMem{RawAllocator}}; + + CopyDescription(Allocator, Desc); + + if (NumStaticResStages > 0) + { + m_pStaticResCache = Allocator.Construct(ResourceCacheContentType::Signature); + + static_assert(std::is_nothrow_constructible::value, + "Constructor of ShaderVariableManagerImplType must be noexcept, so we can safely construct all manager objects"); + m_StaticVarsMgrs = Allocator.ConstructArray(NumStaticResStages, std::ref(*this), std::ref(*m_pStaticResCache)); + } + + return Allocator; + } + +private: + static void ReserveSpaceForDescription(FixedLinearAllocator& Allocator, const PipelineResourceSignatureDesc& Desc) + { Allocator.AddSpace(Desc.NumResources); Allocator.AddSpace(Desc.NumImmutableSamplers); @@ -408,26 +441,8 @@ protected: if (Desc.UseCombinedTextureSamplers) Allocator.AddSpaceForString(Desc.CombinedSamplerSuffix); - - ReserveCustomData(Allocator); - - const auto NumStaticResStages = GetNumStaticResStages(); - if (NumStaticResStages > 0) - { - Allocator.AddSpace(1); - Allocator.AddSpace(NumStaticResStages); - } - - Allocator.Reserve(); - // The memory is now owned by PipelineResourceSignatureBase and will be freed by Destruct(). - m_pRawMemory = decltype(m_pRawMemory){Allocator.ReleaseOwnership(), STDDeleterRawMem{RawAllocator}}; - - CopyDescription(Allocator, Desc); - - return Allocator; } -private: void CopyDescription(FixedLinearAllocator& Allocator, const PipelineResourceSignatureDesc& Desc) noexcept(false) { PipelineResourceDesc* pResources = Allocator.ConstructArray(Desc.NumResources); diff --git a/Graphics/GraphicsEngine/include/ShaderResourceBindingBase.hpp b/Graphics/GraphicsEngine/include/ShaderResourceBindingBase.hpp index 3dc62905..e6dddb0c 100644 --- a/Graphics/GraphicsEngine/include/ShaderResourceBindingBase.hpp +++ b/Graphics/GraphicsEngine/include/ShaderResourceBindingBase.hpp @@ -70,8 +70,6 @@ public: /// \param pRefCounters - Reference counters object that controls the lifetime of this SRB. /// \param pPRS - Pipeline resource signature that this SRB belongs to. - /// \param IsInternal - Flag indicating if the shader resource binding is an internal object and - /// must not keep a strong reference to the pipeline resource signature. ShaderResourceBindingBase(IReferenceCounters* pRefCounters, ResourceSignatureType* pPRS) : TObjectBase{pRefCounters}, m_pPRS{pPRS}, @@ -117,7 +115,6 @@ public: auto& VarDataAllocator = SRBMemAllocator.GetShaderVariableDataAllocator(s); - // Create shader variable manager in place // Initialize vars manager to reference mutable and dynamic variables // Note that the cache has space for all variable types const SHADER_RESOURCE_VARIABLE_TYPE VarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC}; diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp index a0d7f6ed..3375cf2c 100644 --- a/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp @@ -137,12 +137,12 @@ PipelineResourceSignatureD3D12Impl::PipelineResourceSignatureD3D12Impl(IReferenc ValidatePipelineResourceSignatureDescD3D12(Desc); auto& RawAllocator{GetRawAllocator()}; - auto MemPool = ReserveSpace(RawAllocator, Desc, - [&Desc](FixedLinearAllocator& MemPool) // - { - MemPool.AddSpace(Desc.NumResources); - MemPool.AddSpace(Desc.NumImmutableSamplers); - }); + auto MemPool = AllocateInternalObjects(RawAllocator, Desc, + [&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"); @@ -155,11 +155,6 @@ PipelineResourceSignatureD3D12Impl::PipelineResourceSignatureD3D12Impl(IReferenc const auto NumStaticResStages = GetNumStaticResStages(); if (NumStaticResStages > 0) { - m_pStaticResCache = MemPool.Construct(ResourceCacheContentType::Signature); - // Constructor of ShaderVariableManagerD3D12 is noexcept, so we can safely construct all manager objects. - // Moreover, all objects must be constructed if an exception is thrown for Destruct() method to work properly. - m_StaticVarsMgrs = MemPool.ConstructArray(NumStaticResStages, std::ref(*this), std::ref(*m_pStaticResCache)); - m_pStaticResCache->Initialize(RawAllocator, static_cast(StaticResCacheTblSizes.size()), StaticResCacheTblSizes.data()); constexpr SHADER_RESOURCE_VARIABLE_TYPE AllowedVarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_STATIC}; diff --git a/Graphics/GraphicsEngineOpenGL/src/PipelineResourceSignatureGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/PipelineResourceSignatureGLImpl.cpp index 34bb10e5..cd086f20 100644 --- a/Graphics/GraphicsEngineOpenGL/src/PipelineResourceSignatureGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/PipelineResourceSignatureGLImpl.cpp @@ -95,27 +95,21 @@ PipelineResourceSignatureGLImpl::PipelineResourceSignatureGLImpl(IReferenceCount try { auto& RawAllocator{GetRawAllocator()}; - auto MemPool = ReserveSpace(RawAllocator, Desc, - [&](FixedLinearAllocator& MemPool) // - { - MemPool.AddSpace(Desc.NumResources); - MemPool.AddSpace(Desc.NumImmutableSamplers); - }); + auto MemPool = AllocateInternalObjects(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(m_Desc.NumResources); m_ImmutableSamplers = MemPool.ConstructArray(m_Desc.NumImmutableSamplers); - const auto NumStaticResStages = GetNumStaticResStages(); - if (NumStaticResStages > 0) - { - m_pStaticResCache = MemPool.Construct(ResourceCacheContentType::Signature); - m_StaticVarsMgrs = MemPool.ConstructArray(NumStaticResStages, std::ref(*this), std::ref(*m_pStaticResCache)); - } - CreateLayouts(); + const auto NumStaticResStages = GetNumStaticResStages(); if (NumStaticResStages > 0) { constexpr SHADER_RESOURCE_VARIABLE_TYPE AllowedVarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_STATIC}; diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp index 38520c8a..421bbe26 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp @@ -229,12 +229,12 @@ PipelineResourceSignatureVkImpl::PipelineResourceSignatureVkImpl(IReferenceCount try { auto& RawAllocator{GetRawAllocator()}; - auto MemPool = ReserveSpace(RawAllocator, Desc, - [&Desc](FixedLinearAllocator& MemPool) // - { - MemPool.AddSpace(Desc.NumResources); - MemPool.AddSpace(Desc.NumImmutableSamplers); - }); + auto MemPool = AllocateInternalObjects(RawAllocator, Desc, + [&Desc](FixedLinearAllocator& MemPool) // + { + MemPool.AddSpace(Desc.NumResources); + MemPool.AddSpace(Desc.NumImmutableSamplers); + }); m_pResourceAttribs = MemPool.Allocate(m_Desc.NumResources); m_ImmutableSamplers = MemPool.ConstructArray(m_Desc.NumImmutableSamplers); @@ -242,9 +242,6 @@ PipelineResourceSignatureVkImpl::PipelineResourceSignatureVkImpl(IReferenceCount const auto NumStaticResStages = GetNumStaticResStages(); if (NumStaticResStages > 0) { - m_pStaticResCache = MemPool.Construct(ResourceCacheContentType::Signature); - m_StaticVarsMgrs = MemPool.ConstructArray(NumStaticResStages, std::ref(*this), std::ref(*m_pStaticResCache)); - Uint32 StaticResourceCount = 0; // The total number of static resources in all stages // accounting for array sizes. for (Uint32 i = 0; i < Desc.NumResources; ++i) -- cgit v1.2.3