From 6e54a0840da780c3b208bc72294aa33eecc64738 Mon Sep 17 00:00:00 2001 From: assiduous Date: Wed, 10 Mar 2021 20:58:49 -0800 Subject: Moved duplicate shader variable functionality to ShaderVariableBase --- .../include/ShaderVariableManagerGL.hpp | 118 +++------------------ .../src/ShaderVariableManagerGL.cpp | 18 ++-- 2 files changed, 24 insertions(+), 112 deletions(-) (limited to 'Graphics/GraphicsEngineOpenGL') 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 + template + struct GLVariableBase : public ShaderVariableBase { public: - using TBase = ShaderVariableBase; GLVariableBase(ShaderVariableManagerGL& ParentLayout, Uint32 ResIndex) : - TBase{ParentLayout}, - m_ResIndex{ResIndex} + ShaderVariableBase{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(ShaderVariableManagerGL& ParentLayout, Uint32 ResIndex) : - GLVariableBase{ParentLayout, ResIndex} + GLVariableBase{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(ShaderVariableManagerGL& ParentLayout, Uint32 ResIndex) : - GLVariableBase{ParentLayout, ResIndex} + GLVariableBase{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(ShaderVariableManagerGL& ParentLayout, Uint32 ResIndex) : - GLVariableBase{ParentLayout, ResIndex} + GLVariableBase{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(ShaderVariableManagerGL& ParentLayout, Uint32 ResIndex) : - GLVariableBase{ParentLayout, ResIndex} + GLVariableBase{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(reinterpret_cast(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(pResourceMapping, Flags); + ub.BindResources(pResourceMapping, Flags); }, [&](TextureBindInfo& tex) { - tex.BindResources(pResourceMapping, Flags); + tex.BindResources(pResourceMapping, Flags); }, [&](ImageBindInfo& img) { - img.BindResources(pResourceMapping, Flags); + img.BindResources(pResourceMapping, Flags); }, [&](StorageBufferBindInfo& ssbo) { - ssbo.BindResources(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(&Variable) - reinterpret_cast(_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); -- cgit v1.2.3