summaryrefslogtreecommitdiffstats
path: root/Graphics
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2021-03-08 18:27:35 +0000
committerassiduous <assiduous@diligentgraphics.com>2021-03-19 00:38:17 +0000
commit1dfd5042779a493285c397d46f8d903d67c9f972 (patch)
tree4fbb33befdb618afc58a806da4d274596f47261b /Graphics
parentShaderResourceBinding{D3D12, Vk, GL} - removed the remaining duplicate code (diff)
downloadDiligentCore-1dfd5042779a493285c397d46f8d903d67c9f972.tar.gz
DiligentCore-1dfd5042779a493285c397d46f8d903d67c9f972.zip
Resource singature: moved allocation of static resource cache and var managers to PipelineResourceSignatureBase
Diffstat (limited to 'Graphics')
-rw-r--r--Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp57
-rw-r--r--Graphics/GraphicsEngine/include/ShaderResourceBindingBase.hpp3
-rw-r--r--Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp17
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/PipelineResourceSignatureGLImpl.cpp20
-rw-r--r--Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp15
5 files changed, 55 insertions, 57 deletions
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 <typename TReserveCustomData>
- 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<ShaderResourceCacheImplType>(1);
+ Allocator.AddSpace<ShaderVariableManagerImplType>(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<void>{RawAllocator}};
+
+ CopyDescription(Allocator, Desc);
+
+ if (NumStaticResStages > 0)
+ {
+ m_pStaticResCache = Allocator.Construct<ShaderResourceCacheImplType>(ResourceCacheContentType::Signature);
+
+ static_assert(std::is_nothrow_constructible<ShaderVariableManagerImplType, decltype(*this), ShaderResourceCacheImplType&>::value,
+ "Constructor of ShaderVariableManagerImplType must be noexcept, so we can safely construct all manager objects");
+ m_StaticVarsMgrs = Allocator.ConstructArray<ShaderVariableManagerImplType>(NumStaticResStages, std::ref(*this), std::ref(*m_pStaticResCache));
+ }
+
+ return Allocator;
+ }
+
+private:
+ static void ReserveSpaceForDescription(FixedLinearAllocator& Allocator, const PipelineResourceSignatureDesc& Desc)
+ {
Allocator.AddSpace<PipelineResourceDesc>(Desc.NumResources);
Allocator.AddSpace<ImmutableSamplerDesc>(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<ShaderResourceCacheImplType>(1);
- Allocator.AddSpace<ShaderVariableManagerImplType>(NumStaticResStages);
- }
-
- Allocator.Reserve();
- // The memory is now owned by PipelineResourceSignatureBase and will be freed by Destruct().
- m_pRawMemory = decltype(m_pRawMemory){Allocator.ReleaseOwnership(), STDDeleterRawMem<void>{RawAllocator}};
-
- CopyDescription(Allocator, Desc);
-
- return Allocator;
}
-private:
void CopyDescription(FixedLinearAllocator& Allocator, const PipelineResourceSignatureDesc& Desc) noexcept(false)
{
PipelineResourceDesc* pResources = Allocator.ConstructArray<PipelineResourceDesc>(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<ResourceAttribs>(Desc.NumResources);
- MemPool.AddSpace<ImmutableSamplerAttribs>(Desc.NumImmutableSamplers);
- });
+ auto MemPool = AllocateInternalObjects(RawAllocator, Desc,
+ [&Desc](FixedLinearAllocator& MemPool) //
+ {
+ MemPool.AddSpace<ResourceAttribs>(Desc.NumResources);
+ MemPool.AddSpace<ImmutableSamplerAttribs>(Desc.NumImmutableSamplers);
+ });
static_assert(std::is_trivially_destructible<ResourceAttribs>::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<ShaderResourceCacheD3D12>(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<ShaderVariableManagerD3D12>(NumStaticResStages, std::ref(*this), std::ref(*m_pStaticResCache));
-
m_pStaticResCache->Initialize(RawAllocator, static_cast<Uint32>(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<ResourceAttribs>(Desc.NumResources);
- MemPool.AddSpace<SamplerPtr>(Desc.NumImmutableSamplers);
- });
+ auto MemPool = AllocateInternalObjects(RawAllocator, Desc,
+ [&](FixedLinearAllocator& MemPool) //
+ {
+ MemPool.AddSpace<ResourceAttribs>(Desc.NumResources);
+ MemPool.AddSpace<SamplerPtr>(Desc.NumImmutableSamplers);
+ });
static_assert(std::is_trivially_destructible<ResourceAttribs>::value,
"ResourceAttribs objects must be constructed to be properly destructed in case an excpetion is thrown");
m_pResourceAttribs = MemPool.Allocate<ResourceAttribs>(m_Desc.NumResources);
m_ImmutableSamplers = MemPool.ConstructArray<SamplerPtr>(m_Desc.NumImmutableSamplers);
- const auto NumStaticResStages = GetNumStaticResStages();
- if (NumStaticResStages > 0)
- {
- m_pStaticResCache = MemPool.Construct<ShaderResourceCacheGL>(ResourceCacheContentType::Signature);
- m_StaticVarsMgrs = MemPool.ConstructArray<ShaderVariableManagerGL>(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<ResourceAttribs>(Desc.NumResources);
- MemPool.AddSpace<ImmutableSamplerAttribs>(Desc.NumImmutableSamplers);
- });
+ auto MemPool = AllocateInternalObjects(RawAllocator, Desc,
+ [&Desc](FixedLinearAllocator& MemPool) //
+ {
+ MemPool.AddSpace<ResourceAttribs>(Desc.NumResources);
+ MemPool.AddSpace<ImmutableSamplerAttribs>(Desc.NumImmutableSamplers);
+ });
m_pResourceAttribs = MemPool.Allocate<ResourceAttribs>(m_Desc.NumResources);
m_ImmutableSamplers = MemPool.ConstructArray<ImmutableSamplerAttribs>(m_Desc.NumImmutableSamplers);
@@ -242,9 +242,6 @@ PipelineResourceSignatureVkImpl::PipelineResourceSignatureVkImpl(IReferenceCount
const auto NumStaticResStages = GetNumStaticResStages();
if (NumStaticResStages > 0)
{
- m_pStaticResCache = MemPool.Construct<ShaderResourceCacheVk>(ResourceCacheContentType::Signature);
- m_StaticVarsMgrs = MemPool.ConstructArray<ShaderVariableManagerVk>(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)