summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineVulkan
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2021-03-08 06:51:57 +0000
committerassiduous <assiduous@diligentgraphics.com>2021-03-19 00:38:17 +0000
commit3988fe1c2824220145f037a2e41f3e211a311127 (patch)
treeec92d357c54ccebd540abbceda95adb9a1f1ba40 /Graphics/GraphicsEngineVulkan
parentMoved m_SRBMemAllocator to PipelineResourceSignatureBase (diff)
downloadDiligentCore-3988fe1c2824220145f037a2e41f3e211a311127.tar.gz
DiligentCore-3988fe1c2824220145f037a2e41f3e211a311127.zip
Unified implementations of SRB in D3D12, Vk and GL
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
-rw-r--r--Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp20
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp106
2 files changed, 20 insertions, 106 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp
index 1b448b6a..23c9e513 100644
--- a/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp
+++ b/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp
@@ -56,26 +56,6 @@ public:
~ShaderResourceBindingVkImpl();
IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_ShaderResourceBindingVk, TBase)
-
- /// Implementation of IShaderResourceBinding::BindResources() in Vulkan backend.
- virtual void DILIGENT_CALL_TYPE BindResources(Uint32 ShaderFlags, IResourceMapping* pResMapping, Uint32 Flags) override final;
-
- /// Implementation of IShaderResourceBinding::GetVariableByName() in Vulkan backend.
- virtual IShaderResourceVariable* DILIGENT_CALL_TYPE GetVariableByName(SHADER_TYPE ShaderType, const char* Name) override final;
-
- /// Implementation of IShaderResourceBinding::GetVariableCount() in Vulkan backend.
- virtual Uint32 DILIGENT_CALL_TYPE GetVariableCount(SHADER_TYPE ShaderType) const override final;
-
- /// Implementation of IShaderResourceBinding::GetVariableByIndex() in Vulkan backend.
- virtual IShaderResourceVariable* DILIGENT_CALL_TYPE GetVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) override final;
-
- ShaderResourceCacheVk& GetResourceCache() { return m_ShaderResourceCache; }
-
-private:
- void Destruct();
-
- ShaderResourceCacheVk m_ShaderResourceCache;
- ShaderVariableManagerVk* m_pShaderVarMgrs = nullptr; // [m_NumShaders]
};
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp
index 0d5e5396..ead782c1 100644
--- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp
@@ -37,101 +37,35 @@ namespace Diligent
ShaderResourceBindingVkImpl::ShaderResourceBindingVkImpl(IReferenceCounters* pRefCounters,
PipelineResourceSignatureVkImpl* pPRS) :
- // clang-format off
- TBase
- {
- pRefCounters,
- pPRS
- },
- m_ShaderResourceCache{ResourceCacheContentType::SRB}
-// clang-format on
+ TBase{pRefCounters, pPRS}
{
- try
- {
- const auto NumShaders = GetNumShaders();
-
- FixedLinearAllocator MemPool{GetRawAllocator()};
- MemPool.AddSpace<ShaderVariableManagerVk>(NumShaders);
- MemPool.Reserve();
- m_pShaderVarMgrs = MemPool.ConstructArray<ShaderVariableManagerVk>(NumShaders, std::ref(*this), std::ref(m_ShaderResourceCache));
-
- // The memory is now owned by ShaderResourceBindingVkImpl and will be freed by Destruct().
- auto* Ptr = MemPool.ReleaseOwnership();
- VERIFY_EXPR(Ptr == m_pShaderVarMgrs);
- (void)Ptr;
-
- // It is important to construct all objects before initializing them because if an exception is thrown,
- // destructors will be called for all objects
-
- // This will only allocate memory and initialize descriptor sets in the resource cache
- // Resources will be initialized by InitializeResourceMemoryInCache()
- auto& SRBMemAllocator = pPRS->GetSRBMemoryAllocator();
- auto& ResourceCacheDataAllocator = SRBMemAllocator.GetResourceCacheDataAllocator(0);
- pPRS->InitSRBResourceCache(m_ShaderResourceCache, ResourceCacheDataAllocator, pPRS->GetDesc().Name);
-
- for (Uint32 s = 0; s < NumShaders; ++s)
- {
- const auto ShaderType = pPRS->GetActiveShaderStageType(s);
- const auto ShaderInd = GetShaderTypePipelineIndex(ShaderType, pPRS->GetPipelineType());
- const auto MgrInd = m_ActiveShaderStageIndex[ShaderInd];
- VERIFY_EXPR(MgrInd >= 0 && MgrInd < static_cast<int>(NumShaders));
+ const auto NumShaders = GetNumShaders();
- auto& VarDataAllocator = SRBMemAllocator.GetShaderVariableDataAllocator(s);
+ // This will only allocate memory and initialize descriptor sets in the resource cache
+ // Resources will be initialized by InitializeResourceMemoryInCache()
+ auto& SRBMemAllocator = pPRS->GetSRBMemoryAllocator();
+ auto& ResourceCacheDataAllocator = SRBMemAllocator.GetResourceCacheDataAllocator(0);
+ pPRS->InitSRBResourceCache(m_ShaderResourceCache, ResourceCacheDataAllocator, pPRS->GetDesc().Name);
- // 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[MgrInd].Initialize(*pPRS, VarDataAllocator, VarTypes, _countof(VarTypes), ShaderType);
- }
- }
- catch (...)
+ for (Uint32 s = 0; s < NumShaders; ++s)
{
- Destruct();
- throw;
+ const auto ShaderType = pPRS->GetActiveShaderStageType(s);
+ const auto ShaderInd = GetShaderTypePipelineIndex(ShaderType, pPRS->GetPipelineType());
+ const auto MgrInd = m_ActiveShaderStageIndex[ShaderInd];
+ VERIFY_EXPR(MgrInd >= 0 && MgrInd < static_cast<int>(NumShaders));
+
+ 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};
+ m_pShaderVarMgrs[MgrInd].Initialize(*pPRS, VarDataAllocator, VarTypes, _countof(VarTypes), ShaderType);
}
}
ShaderResourceBindingVkImpl::~ShaderResourceBindingVkImpl()
{
- Destruct();
-}
-
-void ShaderResourceBindingVkImpl::Destruct()
-{
- if (m_pShaderVarMgrs != nullptr)
- {
- auto& SRBMemAllocator = GetSignature()->GetSRBMemoryAllocator();
- for (Uint32 s = 0; s < GetNumShaders(); ++s)
- {
- auto& VarDataAllocator = SRBMemAllocator.GetShaderVariableDataAllocator(s);
- m_pShaderVarMgrs[s].Destroy(VarDataAllocator);
- m_pShaderVarMgrs[s].~ShaderVariableManagerVk();
- }
-
- GetRawAllocator().Free(m_pShaderVarMgrs);
- m_pShaderVarMgrs = nullptr;
- }
-}
-
-void ShaderResourceBindingVkImpl::BindResources(Uint32 ShaderFlags, IResourceMapping* pResMapping, Uint32 Flags)
-{
- BindResourcesImpl(ShaderFlags, pResMapping, Flags, m_pShaderVarMgrs);
-}
-
-Uint32 ShaderResourceBindingVkImpl::GetVariableCount(SHADER_TYPE ShaderType) const
-{
- return GetVariableCountImpl(ShaderType, m_pShaderVarMgrs);
-}
-
-IShaderResourceVariable* ShaderResourceBindingVkImpl::GetVariableByName(SHADER_TYPE ShaderType, const Char* Name)
-{
- return GetVariableByNameImpl(ShaderType, Name, m_pShaderVarMgrs);
-}
-
-IShaderResourceVariable* ShaderResourceBindingVkImpl::GetVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index)
-{
- return GetVariableByIndexImpl(ShaderType, Index, m_pShaderVarMgrs);
}
} // namespace Diligent