summaryrefslogtreecommitdiffstats
path: root/Graphics
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-10-20 21:06:33 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-10-20 21:06:33 +0000
commit0c7e8e2efc95362cbc0998558bb41789a3943037 (patch)
treea6a6428334ed7bedd28d0cf8ccf9b15b304e2712 /Graphics
parentImproved exception safety of pipeline state object construction (diff)
downloadDiligentCore-0c7e8e2efc95362cbc0998558bb41789a3943037.tar.gz
DiligentCore-0c7e8e2efc95362cbc0998558bb41789a3943037.zip
Improved exception safety of SRB object creation
Diffstat (limited to 'Graphics')
-rw-r--r--Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.hpp2
-rw-r--r--Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp134
-rw-r--r--Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.hpp2
-rw-r--r--Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp88
-rw-r--r--Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp2
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp88
6 files changed, 206 insertions, 110 deletions
diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.hpp b/Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.hpp
index eb97dfdc..21437e0f 100644
--- a/Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.hpp
+++ b/Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.hpp
@@ -100,6 +100,8 @@ public:
}
private:
+ void Destruct();
+
// The caches are indexed by the shader order in the PSO, not shader index
ShaderResourceCacheD3D11* m_pBoundResourceCaches = nullptr;
ShaderResourceLayoutD3D11* m_pResourceLayouts = nullptr;
diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp
index f7ce059b..46833c81 100644
--- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp
+++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp
@@ -31,6 +31,7 @@
#include "DeviceContextD3D11Impl.hpp"
#include "RenderDeviceD3D11Impl.hpp"
#include "ShaderD3D11Impl.hpp"
+#include "LinearAllocator.hpp"
namespace Diligent
{
@@ -49,69 +50,104 @@ ShaderResourceBindingD3D11Impl::ShaderResourceBindingD3D11Impl(IReferenceCounter
m_bIsStaticResourcesBound{false}
// clang-format on
{
- m_ResourceLayoutIndex.fill(-1);
- m_NumActiveShaders = static_cast<Uint8>(pPSO->GetNumShaderStages());
+ try
+ {
+ m_ResourceLayoutIndex.fill(-1);
+ m_NumActiveShaders = static_cast<Uint8>(pPSO->GetNumShaderStages());
- // clang-format off
- m_pResourceLayouts = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceLayoutD3D11", ShaderResourceLayoutD3D11, m_NumActiveShaders);
- m_pBoundResourceCaches = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceCacheD3D11", ShaderResourceCacheD3D11, m_NumActiveShaders);
- // clang-format on
+ LinearAllocator MemPool{GetRawAllocator()};
+ MemPool.AddSpace<ShaderResourceCacheD3D11>(m_NumActiveShaders);
+ MemPool.AddSpace<ShaderResourceLayoutD3D11>(m_NumActiveShaders);
+
+ MemPool.Reserve();
+
+ m_pBoundResourceCaches = MemPool.ConstructArray<ShaderResourceCacheD3D11>(m_NumActiveShaders);
+
+ // The memory is now owned by ShaderResourceBindingD3D11Impl and will be freed by Destruct().
+ auto* Ptr = MemPool.ReleaseOwnership();
+ VERIFY_EXPR(Ptr == m_pBoundResourceCaches);
+ (void)Ptr;
- const auto& PSODesc = pPSO->GetDesc();
+ m_pResourceLayouts = MemPool.Allocate<ShaderResourceLayoutD3D11>(m_NumActiveShaders);
+ for (Uint8 s = 0; s < m_NumActiveShaders; ++s)
+ new (m_pResourceLayouts + s) ShaderResourceLayoutD3D11{*this, m_pBoundResourceCaches[s]}; // noexcept
- // Reserve memory for resource layouts
- for (Uint8 s = 0; s < m_NumActiveShaders; ++s)
+ // It is important to construct all objects before initializing them because if an exception is thrown,
+ // destructors will be called for all objects
+
+ const auto& PSODesc = pPSO->GetDesc();
+
+ // Reserve memory for resource layouts
+ for (Uint8 s = 0; s < m_NumActiveShaders; ++s)
+ {
+ auto* pShaderD3D11 = pPSO->GetShader(s);
+
+ auto& SRBMemAllocator = pPSO->GetSRBMemoryAllocator();
+ auto& ResCacheDataAllocator = SRBMemAllocator.GetResourceCacheDataAllocator(s);
+ auto& ResLayoutDataAllocator = SRBMemAllocator.GetShaderVariableDataAllocator(s);
+
+ // Initialize resource cache to have enough space to contain all shader resources, including static ones
+ // Static resources are copied before resources are committed
+ const auto& Resources = *pShaderD3D11->GetD3D11Resources();
+ m_pBoundResourceCaches[s].Initialize(Resources, ResCacheDataAllocator);
+
+ // Shader resource layout will only contain dynamic and mutable variables
+ // http://diligentgraphics.com/diligent-engine/architecture/d3d11/shader-resource-cache#Shader-Resource-Cache-Initialization
+ SHADER_RESOURCE_VARIABLE_TYPE VarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC};
+ m_pResourceLayouts[s].Initialize(
+ pShaderD3D11->GetD3D11Resources(),
+ PSODesc.ResourceLayout,
+ VarTypes,
+ _countof(VarTypes),
+ ResCacheDataAllocator,
+ ResLayoutDataAllocator //
+ );
+
+ const auto ShaderType = pShaderD3D11->GetDesc().ShaderType;
+ const auto ShaderInd = GetShaderTypePipelineIndex(ShaderType, PSODesc.PipelineType);
+ VERIFY_EXPR(ShaderType == m_pResourceLayouts[s].GetShaderType());
+ m_ShaderTypes[s] = ShaderType;
+
+ m_ResourceLayoutIndex[ShaderInd] = s;
+ }
+ }
+ catch (...)
{
- auto* pShaderD3D11 = pPSO->GetShader(s);
-
- auto& SRBMemAllocator = pPSO->GetSRBMemoryAllocator();
- auto& ResCacheDataAllocator = SRBMemAllocator.GetResourceCacheDataAllocator(s);
- auto& ResLayoutDataAllocator = SRBMemAllocator.GetShaderVariableDataAllocator(s);
-
- // Initialize resource cache to have enough space to contain all shader resources, including static ones
- // Static resources are copied before resources are committed
- const auto& Resources = *pShaderD3D11->GetD3D11Resources();
- new (m_pBoundResourceCaches + s) ShaderResourceCacheD3D11;
- m_pBoundResourceCaches[s].Initialize(Resources, ResCacheDataAllocator);
-
- // Shader resource layout will only contain dynamic and mutable variables
- // http://diligentgraphics.com/diligent-engine/architecture/d3d11/shader-resource-cache#Shader-Resource-Cache-Initialization
- SHADER_RESOURCE_VARIABLE_TYPE VarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC};
- new (m_pResourceLayouts + s) ShaderResourceLayoutD3D11{*this, m_pBoundResourceCaches[s]};
- m_pResourceLayouts[s].Initialize(
- pShaderD3D11->GetD3D11Resources(),
- PSODesc.ResourceLayout,
- VarTypes,
- _countof(VarTypes),
- ResCacheDataAllocator,
- ResLayoutDataAllocator //
- );
-
- const auto ShaderType = pShaderD3D11->GetDesc().ShaderType;
- const auto ShaderInd = GetShaderTypePipelineIndex(ShaderType, PSODesc.PipelineType);
- VERIFY_EXPR(ShaderType == m_pResourceLayouts[s].GetShaderType());
- m_ShaderTypes[s] = ShaderType;
-
- m_ResourceLayoutIndex[ShaderInd] = s;
+ Destruct();
+ throw;
}
}
ShaderResourceBindingD3D11Impl::~ShaderResourceBindingD3D11Impl()
{
- auto* pPSOD3D11Impl = ValidatedCast<PipelineStateD3D11Impl>(m_pPSO);
- for (Uint32 s = 0; s < m_NumActiveShaders; ++s)
+ Destruct();
+}
+
+void ShaderResourceBindingD3D11Impl::Destruct()
+{
+ if (m_pResourceLayouts != nullptr)
+ {
+ for (Int32 l = 0; l < m_NumActiveShaders; ++l)
+ {
+ m_pResourceLayouts[l].~ShaderResourceLayoutD3D11();
+ }
+ }
+
+ if (m_pBoundResourceCaches != nullptr)
{
- auto& Allocator = pPSOD3D11Impl->GetSRBMemoryAllocator().GetResourceCacheDataAllocator(s);
- m_pBoundResourceCaches[s].Destroy(Allocator);
- m_pBoundResourceCaches[s].~ShaderResourceCacheD3D11();
+ auto& SRBMemAllocator = m_pPSO->GetSRBMemoryAllocator();
+ for (Uint32 s = 0; s < m_NumActiveShaders; ++s)
+ {
+ auto& Allocator = SRBMemAllocator.GetResourceCacheDataAllocator(s);
+ m_pBoundResourceCaches[s].Destroy(Allocator);
+ m_pBoundResourceCaches[s].~ShaderResourceCacheD3D11();
+ }
}
- GetRawAllocator().Free(m_pBoundResourceCaches);
- for (Int32 l = 0; l < m_NumActiveShaders; ++l)
+ if (void* pRawMem = m_pBoundResourceCaches)
{
- m_pResourceLayouts[l].~ShaderResourceLayoutD3D11();
+ GetRawAllocator().Free(pRawMem);
}
- GetRawAllocator().Free(m_pResourceLayouts);
}
IMPLEMENT_QUERY_INTERFACE(ShaderResourceBindingD3D11Impl, IID_ShaderResourceBindingD3D11, TBase)
diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.hpp
index 846cb329..7be3372d 100644
--- a/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.hpp
+++ b/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.hpp
@@ -78,6 +78,8 @@ public:
}
private:
+ void Destruct();
+
ShaderResourceCacheD3D12 m_ShaderResourceCache;
ShaderVariableManagerD3D12* m_pShaderVarMgrs = nullptr;
diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp
index 1c5ae5f5..1511bd01 100644
--- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp
@@ -30,6 +30,7 @@
#include "PipelineStateD3D12Impl.hpp"
#include "ShaderD3D12Impl.hpp"
#include "RenderDeviceD3D12Impl.hpp"
+#include "LinearAllocator.hpp"
namespace Diligent
{
@@ -48,48 +49,73 @@ ShaderResourceBindingD3D12Impl::ShaderResourceBindingD3D12Impl(IReferenceCounter
m_NumShaders {static_cast<decltype(m_NumShaders)>(pPSO->GetNumShaderStages())}
// clang-format on
{
- m_ResourceLayoutIndex.fill(-1);
+ try
+ {
+ m_ResourceLayoutIndex.fill(-1);
+
+ LinearAllocator MemPool{GetRawAllocator()};
+ MemPool.AddSpace<ShaderVariableManagerD3D12>(m_NumShaders);
+ MemPool.Reserve();
+ m_pShaderVarMgrs = MemPool.ConstructArray<ShaderVariableManagerD3D12>(m_NumShaders, std::ref(*this), std::ref(m_ShaderResourceCache));
- auto* pRenderDeviceD3D12Impl = ValidatedCast<RenderDeviceD3D12Impl>(pPSO->GetDevice());
- auto& ResCacheDataAllocator = pPSO->GetSRBMemoryAllocator().GetResourceCacheDataAllocator(0);
- pPSO->GetRootSignature().InitResourceCache(pRenderDeviceD3D12Impl, m_ShaderResourceCache, ResCacheDataAllocator);
+ // The memory is now owned by ShaderResourceBindingD3D12Impl and will be freed by Destruct().
+ auto* Ptr = MemPool.ReleaseOwnership();
+ VERIFY_EXPR(Ptr == m_pShaderVarMgrs);
+ (void)Ptr;
- m_pShaderVarMgrs = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderVariableManagerD3D12", ShaderVariableManagerD3D12, m_NumShaders);
+ // It is important to construct all objects before initializing them because if an exception is thrown,
+ // destructors will be called for all objects
- for (Uint32 s = 0; s < m_NumShaders; ++s)
+ auto* pRenderDeviceD3D12Impl = ValidatedCast<RenderDeviceD3D12Impl>(pPSO->GetDevice());
+ auto& ResCacheDataAllocator = pPSO->GetSRBMemoryAllocator().GetResourceCacheDataAllocator(0);
+ pPSO->GetRootSignature().InitResourceCache(pRenderDeviceD3D12Impl, m_ShaderResourceCache, ResCacheDataAllocator);
+
+ for (Uint32 s = 0; s < m_NumShaders; ++s)
+ {
+ const auto ShaderType = pPSO->GetShaderStageType(s);
+ const auto& SrcLayout = pPSO->GetShaderResLayout(s);
+ const auto ShaderInd = GetShaderTypePipelineIndex(ShaderType, pPSO->GetDesc().PipelineType);
+
+ auto& VarDataAllocator = pPSO->GetSRBMemoryAllocator().GetShaderVariableDataAllocator(s);
+
+ // http://diligentgraphics.com/diligent-engine/architecture/d3d12/shader-resource-layout#Initializing-Resource-Layouts-in-a-Shader-Resource-Binding-Object
+ const SHADER_RESOURCE_VARIABLE_TYPE AllowedVarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC};
+ m_pShaderVarMgrs[s].Initialize(
+ SrcLayout,
+ VarDataAllocator,
+ AllowedVarTypes,
+ _countof(AllowedVarTypes) //
+ );
+
+ m_ResourceLayoutIndex[ShaderInd] = static_cast<Int8>(s);
+ }
+ }
+ catch (...)
{
- auto ShaderType = pPSO->GetShaderStageType(s);
- auto ShaderInd = GetShaderTypePipelineIndex(ShaderType, pPSO->GetDesc().PipelineType);
-
- auto& VarDataAllocator = pPSO->GetSRBMemoryAllocator().GetShaderVariableDataAllocator(s);
-
- // http://diligentgraphics.com/diligent-engine/architecture/d3d12/shader-resource-layout#Initializing-Resource-Layouts-in-a-Shader-Resource-Binding-Object
- const SHADER_RESOURCE_VARIABLE_TYPE AllowedVarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC};
- const auto& SrcLayout = pPSO->GetShaderResLayout(s);
- // Create shader variable manager in place
- new (m_pShaderVarMgrs + s) ShaderVariableManagerD3D12{*this, m_ShaderResourceCache};
- m_pShaderVarMgrs[s].Initialize(
- SrcLayout,
- VarDataAllocator,
- AllowedVarTypes,
- _countof(AllowedVarTypes) //
- );
-
- m_ResourceLayoutIndex[ShaderInd] = static_cast<Int8>(s);
+ Destruct();
+ throw;
}
}
+
ShaderResourceBindingD3D12Impl::~ShaderResourceBindingD3D12Impl()
{
- auto* pPSO = ValidatedCast<PipelineStateD3D12Impl>(m_pPSO);
- for (Uint32 s = 0; s < m_NumShaders; ++s)
+ Destruct();
+}
+
+void ShaderResourceBindingD3D12Impl::Destruct()
+{
+ if (m_pShaderVarMgrs != nullptr)
{
- auto& VarDataAllocator = pPSO->GetSRBMemoryAllocator().GetShaderVariableDataAllocator(s);
- m_pShaderVarMgrs[s].Destroy(VarDataAllocator);
- m_pShaderVarMgrs[s].~ShaderVariableManagerD3D12();
+ auto& SRBMemAllocator = m_pPSO->GetSRBMemoryAllocator();
+ for (Uint32 s = 0; s < m_NumShaders; ++s)
+ {
+ auto& VarDataAllocator = SRBMemAllocator.GetShaderVariableDataAllocator(s);
+ m_pShaderVarMgrs[s].Destroy(VarDataAllocator);
+ m_pShaderVarMgrs[s].~ShaderVariableManagerD3D12();
+ }
+ GetRawAllocator().Free(m_pShaderVarMgrs);
}
-
- GetRawAllocator().Free(m_pShaderVarMgrs);
}
IMPLEMENT_QUERY_INTERFACE(ShaderResourceBindingD3D12Impl, IID_ShaderResourceBindingD3D12, TBase)
diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp
index 026bb9da..00f2c33a 100644
--- a/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp
+++ b/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp
@@ -76,6 +76,8 @@ public:
bool StaticResourcesInitialized() const { return m_bStaticResourcesInitialized; }
private:
+ void Destruct();
+
ShaderResourceCacheVk m_ShaderResourceCache;
ShaderVariableManagerVk* m_pShaderVarMgrs = nullptr;
diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp
index 21b216db..3e4a65cf 100644
--- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp
@@ -30,6 +30,7 @@
#include "PipelineStateVkImpl.hpp"
#include "ShaderVkImpl.hpp"
#include "RenderDeviceVkImpl.hpp"
+#include "LinearAllocator.hpp"
namespace Diligent
{
@@ -47,52 +48,79 @@ ShaderResourceBindingVkImpl::ShaderResourceBindingVkImpl(IReferenceCounters* pR
m_ShaderResourceCache{ShaderResourceCacheVk::DbgCacheContentType::SRBResources}
// clang-format on
{
- m_ResourceLayoutIndex.fill(-1);
+ try
+ {
+ m_ResourceLayoutIndex.fill(-1);
- m_NumShaders = static_cast<decltype(m_NumShaders)>(pPSO->GetNumShaderStages());
+ m_NumShaders = static_cast<decltype(m_NumShaders)>(pPSO->GetNumShaderStages());
- auto* pRenderDeviceVkImpl = pPSO->GetDevice();
- // This will only allocate memory and initialize descriptor sets in the resource cache
- // Resources will be initialized by InitializeResourceMemoryInCache()
- auto& ResourceCacheDataAllocator = pPSO->GetSRBMemoryAllocator().GetResourceCacheDataAllocator(0);
- pPSO->GetPipelineLayout().InitResourceCache(pRenderDeviceVkImpl, m_ShaderResourceCache, ResourceCacheDataAllocator, pPSO->GetDesc().Name);
+ LinearAllocator MemPool{GetRawAllocator()};
+ MemPool.AddSpace<ShaderVariableManagerVk>(m_NumShaders);
+ MemPool.Reserve();
+ m_pShaderVarMgrs = MemPool.ConstructArray<ShaderVariableManagerVk>(m_NumShaders, std::ref(*this), std::ref(m_ShaderResourceCache));
- m_pShaderVarMgrs = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderVariableManagerVk", ShaderVariableManagerVk, m_NumShaders);
+ // The memory is now owned by ShaderResourceBindingVkImpl and will be freed by Destruct().
+ auto* Ptr = MemPool.ReleaseOwnership();
+ VERIFY_EXPR(Ptr == m_pShaderVarMgrs);
+ (void)Ptr;
- for (Uint32 s = 0; s < m_NumShaders; ++s)
- {
- auto ShaderInd = GetShaderTypePipelineIndex(pPSO->GetShaderStageType(s), pPSO->GetDesc().PipelineType);
+ // It is important to construct all objects before initializing them because if an exception is thrown,
+ // destructors will be called for all objects
- m_ResourceLayoutIndex[ShaderInd] = static_cast<Int8>(s);
+ auto* pRenderDeviceVkImpl = pPSO->GetDevice();
+ // This will only allocate memory and initialize descriptor sets in the resource cache
+ // Resources will be initialized by InitializeResourceMemoryInCache()
+ auto& ResourceCacheDataAllocator = pPSO->GetSRBMemoryAllocator().GetResourceCacheDataAllocator(0);
+ pPSO->GetPipelineLayout().InitResourceCache(pRenderDeviceVkImpl, m_ShaderResourceCache, ResourceCacheDataAllocator, pPSO->GetDesc().Name);
- auto& VarDataAllocator = pPSO->GetSRBMemoryAllocator().GetShaderVariableDataAllocator(s);
+ for (Uint32 s = 0; s < m_NumShaders; ++s)
+ {
+ auto ShaderInd = GetShaderTypePipelineIndex(pPSO->GetShaderStageType(s), pPSO->GetDesc().PipelineType);
- const auto& SrcLayout = pPSO->GetShaderResLayout(s);
- // Use source layout to initialize resource memory in the cache
- SrcLayout.InitializeResourceMemoryInCache(m_ShaderResourceCache);
+ m_ResourceLayoutIndex[ShaderInd] = static_cast<Int8>(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};
- new (m_pShaderVarMgrs + s) ShaderVariableManagerVk{*this, m_ShaderResourceCache};
- m_pShaderVarMgrs[s].Initialize(SrcLayout, VarDataAllocator, VarTypes, _countof(VarTypes));
- }
+ auto& VarDataAllocator = pPSO->GetSRBMemoryAllocator().GetShaderVariableDataAllocator(s);
+
+ const auto& SrcLayout = pPSO->GetShaderResLayout(s);
+ // Use source layout to initialize resource memory in the cache
+ SrcLayout.InitializeResourceMemoryInCache(m_ShaderResourceCache);
+
+ // 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};
+ m_pShaderVarMgrs[s].Initialize(SrcLayout, VarDataAllocator, VarTypes, _countof(VarTypes));
+ }
#ifdef DILIGENT_DEBUG
- m_ShaderResourceCache.DbgVerifyResourceInitialization();
+ m_ShaderResourceCache.DbgVerifyResourceInitialization();
#endif
+ }
+ catch (...)
+ {
+ Destruct();
+ throw;
+ }
}
ShaderResourceBindingVkImpl::~ShaderResourceBindingVkImpl()
{
- for (Uint32 s = 0; s < m_NumShaders; ++s)
+ Destruct();
+}
+
+void ShaderResourceBindingVkImpl::Destruct()
+{
+ if (m_pShaderVarMgrs != nullptr)
{
- auto& VarDataAllocator = m_pPSO->GetSRBMemoryAllocator().GetShaderVariableDataAllocator(s);
- m_pShaderVarMgrs[s].DestroyVariables(VarDataAllocator);
- m_pShaderVarMgrs[s].~ShaderVariableManagerVk();
- }
+ auto& SRBMemAllocator = m_pPSO->GetSRBMemoryAllocator();
+ for (Uint32 s = 0; s < m_NumShaders; ++s)
+ {
+ auto& VarDataAllocator = SRBMemAllocator.GetShaderVariableDataAllocator(s);
+ m_pShaderVarMgrs[s].DestroyVariables(VarDataAllocator);
+ m_pShaderVarMgrs[s].~ShaderVariableManagerVk();
+ }
- GetRawAllocator().Free(m_pShaderVarMgrs);
+ GetRawAllocator().Free(m_pShaderVarMgrs);
+ }
}
IMPLEMENT_QUERY_INTERFACE(ShaderResourceBindingVkImpl, IID_ShaderResourceBindingVk, TBase)