summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineOpenGL
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/GraphicsEngineOpenGL
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/GraphicsEngineOpenGL')
-rw-r--r--Graphics/GraphicsEngineOpenGL/include/ShaderResourceBindingGLImpl.hpp26
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/ShaderResourceBindingGLImpl.cpp106
2 files changed, 20 insertions, 112 deletions
diff --git a/Graphics/GraphicsEngineOpenGL/include/ShaderResourceBindingGLImpl.hpp b/Graphics/GraphicsEngineOpenGL/include/ShaderResourceBindingGLImpl.hpp
index 1e5c5753..40fae9a4 100644
--- a/Graphics/GraphicsEngineOpenGL/include/ShaderResourceBindingGLImpl.hpp
+++ b/Graphics/GraphicsEngineOpenGL/include/ShaderResourceBindingGLImpl.hpp
@@ -55,32 +55,6 @@ public:
~ShaderResourceBindingGLImpl();
virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final;
-
- /// Implementation of IShaderResourceBinding::BindResources() in OpenGL backend.
- virtual void DILIGENT_CALL_TYPE BindResources(Uint32 ShaderFlags,
- IResourceMapping* pResMapping,
- Uint32 Flags) override final;
-
- /// Implementation of IShaderResourceBinding::GetVariableByName() in OpenGL backend.
- virtual IShaderResourceVariable* DILIGENT_CALL_TYPE GetVariableByName(SHADER_TYPE ShaderType, const char* Name) override final;
-
- /// Implementation of IShaderResourceBinding::GetVariableCount() in OpenGL backend.
- virtual Uint32 DILIGENT_CALL_TYPE GetVariableCount(SHADER_TYPE ShaderType) const override final;
-
- /// Implementation of IShaderResourceBinding::GetVariableByIndex() in OpenGL backend.
- virtual IShaderResourceVariable* DILIGENT_CALL_TYPE GetVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) override final;
-
- ShaderResourceCacheGL& GetResourceCache() { return m_ShaderResourceCache; }
- ShaderResourceCacheGL const& GetResourceCache() const { return m_ShaderResourceCache; }
-
-private:
- void Destruct();
-
- // The resource cache holds resource bindings for all variables
- ShaderResourceCacheGL m_ShaderResourceCache;
-
- // The resource layout only references mutable and dynamic variables
- ShaderVariableManagerGL* m_pShaderVarMgrs = nullptr; // [GetNumShaders()]
};
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineOpenGL/src/ShaderResourceBindingGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/ShaderResourceBindingGLImpl.cpp
index 27f56bdc..ba89bf69 100644
--- a/Graphics/GraphicsEngineOpenGL/src/ShaderResourceBindingGLImpl.cpp
+++ b/Graphics/GraphicsEngineOpenGL/src/ShaderResourceBindingGLImpl.cpp
@@ -41,103 +41,37 @@ namespace Diligent
ShaderResourceBindingGLImpl::ShaderResourceBindingGLImpl(IReferenceCounters* pRefCounters,
PipelineResourceSignatureGLImpl* 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<ShaderVariableManagerGL>(NumShaders);
- MemPool.Reserve();
- m_pShaderVarMgrs = MemPool.ConstructArray<ShaderVariableManagerGL>(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);
-
- 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);
- // 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);
}
}
ShaderResourceBindingGLImpl::~ShaderResourceBindingGLImpl()
{
- Destruct();
-}
-
-void ShaderResourceBindingGLImpl::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].~ShaderVariableManagerGL();
- }
-
- GetRawAllocator().Free(m_pShaderVarMgrs);
- m_pShaderVarMgrs = nullptr;
- }
}
IMPLEMENT_QUERY_INTERFACE(ShaderResourceBindingGLImpl, IID_ShaderResourceBindingGL, TBase)
-void ShaderResourceBindingGLImpl::BindResources(Uint32 ShaderFlags, IResourceMapping* pResMapping, Uint32 Flags)
-{
- BindResourcesImpl(ShaderFlags, pResMapping, Flags, m_pShaderVarMgrs);
-}
-
-IShaderResourceVariable* ShaderResourceBindingGLImpl::GetVariableByName(SHADER_TYPE ShaderType, const char* Name)
-{
- return GetVariableByNameImpl(ShaderType, Name, m_pShaderVarMgrs);
-}
-
-Uint32 ShaderResourceBindingGLImpl::GetVariableCount(SHADER_TYPE ShaderType) const
-{
- return GetVariableCountImpl(ShaderType, m_pShaderVarMgrs);
-}
-
-IShaderResourceVariable* ShaderResourceBindingGLImpl::GetVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index)
-{
- return GetVariableByIndexImpl(ShaderType, Index, m_pShaderVarMgrs);
-}
-
} // namespace Diligent