summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineOpenGL
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2021-03-11 04:58:49 +0000
committerassiduous <assiduous@diligentgraphics.com>2021-03-19 00:38:20 +0000
commit6e54a0840da780c3b208bc72294aa33eecc64738 (patch)
tree2b3cd3d88cf89a3fb7e16a73692c25af15f2273a /Graphics/GraphicsEngineOpenGL
parentVk backend: moved resource binding logic to variable manager and cache (diff)
downloadDiligentCore-6e54a0840da780c3b208bc72294aa33eecc64738.tar.gz
DiligentCore-6e54a0840da780c3b208bc72294aa33eecc64738.zip
Moved duplicate shader variable functionality to ShaderVariableBase
Diffstat (limited to 'Graphics/GraphicsEngineOpenGL')
-rw-r--r--Graphics/GraphicsEngineOpenGL/include/ShaderVariableManagerGL.hpp118
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/ShaderVariableManagerGL.cpp18
2 files changed, 24 insertions, 112 deletions
diff --git a/Graphics/GraphicsEngineOpenGL/include/ShaderVariableManagerGL.hpp b/Graphics/GraphicsEngineOpenGL/include/ShaderVariableManagerGL.hpp
index e028f566..cadf1eee 100644
--- a/Graphics/GraphicsEngineOpenGL/include/ShaderVariableManagerGL.hpp
+++ b/Graphics/GraphicsEngineOpenGL/include/ShaderVariableManagerGL.hpp
@@ -63,7 +63,7 @@ namespace Diligent
class PipelineResourceSignatureGLImpl;
-// sizeof(ShaderVariableManagerGL) == 48 (x64, msvc, Release)
+// sizeof(ShaderVariableManagerGL) == 40 (x64, msvc, Release)
class ShaderVariableManagerGL
{
public:
@@ -99,68 +99,28 @@ public:
// These two methods can't be implemented in the header because they depend on PipelineResourceSignatureGLImpl
const PipelineResourceDesc& GetResourceDesc(Uint32 Index) const;
- const ResourceAttribs& GetAttribs(Uint32 Index) const;
+ const ResourceAttribs& GetResourceAttribs(Uint32 Index) const;
-
- struct GLVariableBase : public ShaderVariableBase<ShaderVariableManagerGL>
+ template <typename ThisImplType>
+ struct GLVariableBase : public ShaderVariableBase<ThisImplType, ShaderVariableManagerGL>
{
public:
- using TBase = ShaderVariableBase<ShaderVariableManagerGL>;
GLVariableBase(ShaderVariableManagerGL& ParentLayout, Uint32 ResIndex) :
- TBase{ParentLayout},
- m_ResIndex{ResIndex}
+ ShaderVariableBase<ThisImplType, ShaderVariableManagerGL>{ParentLayout, ResIndex}
{}
- const PipelineResourceDesc& GetDesc() const { return m_ParentManager.GetResourceDesc(m_ResIndex); }
- const ResourceAttribs& GetAttribs() const { return m_ParentManager.GetAttribs(m_ResIndex); }
-
- virtual SHADER_RESOURCE_VARIABLE_TYPE DILIGENT_CALL_TYPE GetType() const override final
- {
- return GetDesc().VarType;
- }
-
- virtual void DILIGENT_CALL_TYPE GetResourceDesc(ShaderResourceDesc& ResourceDesc) const override final
- {
- const auto& Desc = GetDesc();
- ResourceDesc.Name = Desc.Name;
- ResourceDesc.Type = Desc.ResourceType;
- ResourceDesc.ArraySize = Desc.ArraySize;
- }
-
- virtual Uint32 DILIGENT_CALL_TYPE GetIndex() const override final
- {
- return m_ParentManager.GetVariableIndex(*this);
- }
-
- private:
- const Uint32 m_ResIndex;
+ const ResourceAttribs& GetAttribs() const { return this->m_ParentManager.GetResourceAttribs(this->m_ResIndex); }
};
- struct UniformBuffBindInfo final : GLVariableBase
+ struct UniformBuffBindInfo final : GLVariableBase<UniformBuffBindInfo>
{
UniformBuffBindInfo(ShaderVariableManagerGL& ParentLayout, Uint32 ResIndex) :
- GLVariableBase{ParentLayout, ResIndex}
+ GLVariableBase<UniformBuffBindInfo>{ParentLayout, ResIndex}
{}
- // Non-virtual function
void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex);
- virtual void DILIGENT_CALL_TYPE Set(IDeviceObject* pObject) override final
- {
- BindResource(pObject, 0);
- }
-
- virtual void DILIGENT_CALL_TYPE SetArray(IDeviceObject* const* ppObjects,
- Uint32 FirstElement,
- Uint32 NumElements) override final
- {
- const auto& Desc = GetDesc();
- VerifyAndCorrectSetArrayArguments(Desc.Name, Desc.ArraySize, FirstElement, NumElements);
- for (Uint32 elem = 0; elem < NumElements; ++elem)
- BindResource(ppObjects[elem], FirstElement + elem);
- }
-
virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final
{
VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize);
@@ -169,30 +129,14 @@ public:
};
- struct TextureBindInfo final : GLVariableBase
+ struct TextureBindInfo final : GLVariableBase<TextureBindInfo>
{
TextureBindInfo(ShaderVariableManagerGL& ParentLayout, Uint32 ResIndex) :
- GLVariableBase{ParentLayout, ResIndex}
+ GLVariableBase<TextureBindInfo>{ParentLayout, ResIndex}
{}
- // Non-virtual function
void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex);
- virtual void DILIGENT_CALL_TYPE Set(IDeviceObject* pObject) override final
- {
- BindResource(pObject, 0);
- }
-
- virtual void DILIGENT_CALL_TYPE SetArray(IDeviceObject* const* ppObjects,
- Uint32 FirstElement,
- Uint32 NumElements) override final
- {
- const auto& Desc = GetDesc();
- VerifyAndCorrectSetArrayArguments(Desc.Name, Desc.ArraySize, FirstElement, NumElements);
- for (Uint32 elem = 0; elem < NumElements; ++elem)
- BindResource(ppObjects[elem], FirstElement + elem);
- }
-
virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final
{
const auto& Desc = GetDesc();
@@ -203,30 +147,14 @@ public:
};
- struct ImageBindInfo final : GLVariableBase
+ struct ImageBindInfo final : GLVariableBase<ImageBindInfo>
{
ImageBindInfo(ShaderVariableManagerGL& ParentLayout, Uint32 ResIndex) :
- GLVariableBase{ParentLayout, ResIndex}
+ GLVariableBase<ImageBindInfo>{ParentLayout, ResIndex}
{}
- // Provide non-virtual function
void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex);
- virtual void DILIGENT_CALL_TYPE Set(IDeviceObject* pObject) override final
- {
- BindResource(pObject, 0);
- }
-
- virtual void DILIGENT_CALL_TYPE SetArray(IDeviceObject* const* ppObjects,
- Uint32 FirstElement,
- Uint32 NumElements) override final
- {
- const auto& Desc = GetDesc();
- VerifyAndCorrectSetArrayArguments(Desc.Name, Desc.ArraySize, FirstElement, NumElements);
- for (Uint32 elem = 0; elem < NumElements; ++elem)
- BindResource(ppObjects[elem], FirstElement + elem);
- }
-
virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final
{
const auto& Desc = GetDesc();
@@ -237,30 +165,14 @@ public:
};
- struct StorageBufferBindInfo final : GLVariableBase
+ struct StorageBufferBindInfo final : GLVariableBase<StorageBufferBindInfo>
{
StorageBufferBindInfo(ShaderVariableManagerGL& ParentLayout, Uint32 ResIndex) :
- GLVariableBase{ParentLayout, ResIndex}
+ GLVariableBase<StorageBufferBindInfo>{ParentLayout, ResIndex}
{}
- // Non-virtual function
void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex);
- virtual void DILIGENT_CALL_TYPE Set(IDeviceObject* pObject) override final
- {
- BindResource(pObject, 0);
- }
-
- virtual void DILIGENT_CALL_TYPE SetArray(IDeviceObject* const* ppObjects,
- Uint32 FirstElement,
- Uint32 NumElements) override final
- {
- const auto& Desc = GetDesc();
- VerifyAndCorrectSetArrayArguments(Desc.Name, Desc.ArraySize, FirstElement, NumElements);
- for (Uint32 elem = 0; elem < NumElements; ++elem)
- BindResource(ppObjects[elem], FirstElement + elem);
- }
-
virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final
{
VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize);
@@ -297,7 +209,7 @@ public:
return reinterpret_cast<const ResourceType*>(reinterpret_cast<const Uint8*>(m_ResourceBuffer) + Offset)[ResIndex];
}
- Uint32 GetVariableIndex(const GLVariableBase& Var) const;
+ Uint32 GetVariableIndex(const IShaderResourceVariable& Var) const;
private:
struct ResourceCounters
diff --git a/Graphics/GraphicsEngineOpenGL/src/ShaderVariableManagerGL.cpp b/Graphics/GraphicsEngineOpenGL/src/ShaderVariableManagerGL.cpp
index 4294f2e8..1ad70b17 100644
--- a/Graphics/GraphicsEngineOpenGL/src/ShaderVariableManagerGL.cpp
+++ b/Graphics/GraphicsEngineOpenGL/src/ShaderVariableManagerGL.cpp
@@ -97,7 +97,7 @@ void ShaderVariableManagerGL::Initialize(const PipelineResourceSignatureGLImpl&
m_pDbgAllocator = &Allocator;
#endif
- auto Counters = CountResources(Signature, AllowedVarTypes, NumAllowedTypes, ShaderType);
+ const auto Counters = CountResources(Signature, AllowedVarTypes, NumAllowedTypes, ShaderType);
m_pSignature = &Signature;
@@ -254,7 +254,7 @@ void ShaderVariableManagerGL::TextureBindInfo::BindResource(IDeviceObject* pView
RESOURCE_DIM_UNDEFINED, false, CachedTexSampler.pView.RawPtr());
if (ImmutableSamplerAssigned && ResourceCache.GetContentType() == ResourceCacheContentType::SRB)
{
- VERIFY(CachedTexSampler.pSampler != nullptr, "Immutable samplers must be initialized in the SRB cache by PipelineResourceSignatureGLImpl::InitializeSRBResourceCache!");
+ VERIFY(CachedTexSampler.pSampler != nullptr, "Immutable samplers must be initialized in the SRB cache by PipelineResourceSignatureGLImpl::InitSRBResourceCache!");
}
if (Desc.ResourceType == SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT)
{
@@ -403,16 +403,16 @@ void ShaderVariableManagerGL::BindResources(IResourceMapping* pResourceMapping,
HandleResources(
[&](UniformBuffBindInfo& ub) {
- ub.BindResources<UniformBuffBindInfo>(pResourceMapping, Flags);
+ ub.BindResources(pResourceMapping, Flags);
},
[&](TextureBindInfo& tex) {
- tex.BindResources<TextureBindInfo>(pResourceMapping, Flags);
+ tex.BindResources(pResourceMapping, Flags);
},
[&](ImageBindInfo& img) {
- img.BindResources<ImageBindInfo>(pResourceMapping, Flags);
+ img.BindResources(pResourceMapping, Flags);
},
[&](StorageBufferBindInfo& ssbo) {
- ssbo.BindResources<StorageBufferBindInfo>(pResourceMapping, Flags);
+ ssbo.BindResources(pResourceMapping, Flags);
});
}
@@ -505,7 +505,7 @@ IShaderResourceVariable* ShaderVariableManagerGL::GetVariable(Uint32 Index) cons
class ShaderVariableIndexLocator
{
public:
- ShaderVariableIndexLocator(const ShaderVariableManagerGL& _Layout, const ShaderVariableManagerGL::GLVariableBase& Variable) :
+ ShaderVariableIndexLocator(const ShaderVariableManagerGL& _Layout, const IShaderResourceVariable& Variable) :
// clang-format off
Layout {_Layout},
VarOffset(reinterpret_cast<const Uint8*>(&Variable) - reinterpret_cast<const Uint8*>(_Layout.m_ResourceBuffer))
@@ -542,7 +542,7 @@ private:
};
-Uint32 ShaderVariableManagerGL::GetVariableIndex(const GLVariableBase& Var) const
+Uint32 ShaderVariableManagerGL::GetVariableIndex(const IShaderResourceVariable& Var) const
{
if (!m_ResourceBuffer)
{
@@ -574,7 +574,7 @@ const PipelineResourceDesc& ShaderVariableManagerGL::GetResourceDesc(Uint32 Inde
return m_pSignature->GetResourceDesc(Index);
}
-const ShaderVariableManagerGL::ResourceAttribs& ShaderVariableManagerGL::GetAttribs(Uint32 Index) const
+const ShaderVariableManagerGL::ResourceAttribs& ShaderVariableManagerGL::GetResourceAttribs(Uint32 Index) const
{
VERIFY_EXPR(m_pSignature);
return m_pSignature->GetResourceAttribs(Index);